all repos — myks @ main

A barebones in-memory keystore in 125~ lines of actual code.

e70491d7
change BiRabittoh to birabittoh
Marco Andronaco andronacomarco@gmail.com
Thu, 10 Oct 2024 09:47:06 +0200
ecfcd30b
handle negative cleanupIntervals
Marco Andronaco andronacomarco@gmail.com
Thu, 10 Oct 2024 09:05:53 +0200
74aa0b41
initial commit
Marco Andronaco andronacomarco@gmail.com
Thu, 10 Oct 2024 01:55:49 +0200
myks
----

A barebones in-memory keystore in 125~ lines of actual code.


FEATURES

• Set key-value pairs with a given expiration.
• Set key-value pairs without a given expiration.
• Get values of any type (uses Go generics).
• Delete unwanted values.
• Probably not memory-safe!


INSTALLING

`go get github.com/birabittoh/myks`


USAGE

`ks := myks.New[string](5 * time.Minute)` creates a new instance and
starts a goroutine that cleans up expired entries every 5 minutes.
You can also pass `0` to disable the cleanup goroutine altogether.

`go ks.StartCleanup(10 * time.Minute)` starts the cleanup goroutine
at a later stage or changes its interval, if it's already started.

`ks.Set("key", "value", 2 * time.Minute)` sets a new key-value pair
with an expiration of 2 minutes.
You can also pass `0` to keep that value until the app is stopped.

`ks.Get("key")` returns a pointer to the set value and an error
value (either nil, `ks.ErrNotFound` or `ks.ErrExpired`).

`ks.Delete("key")` deletes a given key-value pair.

`ks.Keys()` returns an iterator for all keys that are not expired.


LICENSE

myks is licensed under MIT.
clone
git clone https://git.birabittoh.duckdns.org/myks.git