Memkey is a fast, lightweight in-memory key-value store for Go.
- 🚀 Fast, lightweight in-memory key-value store.
- ⏰ Optional TTL per key.
- ✨ Background cleanup to remove expired keys.
- 🔐 Concurrent-safe.
go get -u github.com/byterio/memkeypackage main
import (
"fmt"
"time"
"github.com/byterio/memkey"
)
func main() {
mk := memkey.New()
defer mk.Close()
mk.Set("ping", []byte("pong"), 5*time.Second)
mk.Set("foo", []byte("bar"), 0)
if mk.Has("ping") {
v, _ := mk.Get("ping")
fmt.Println(string(v)) // prints "pong"
}
time.Sleep(6 * time.Second)
if mk.Has("foo") {
v, _ := mk.Get("foo")
fmt.Println(string(v)) // prints "bar"
}
if !mk.Has("ping") {
fmt.Println("expired")
}
}| Benchmark | Iterations | ns/op | B/op | allocs/op |
|---|---|---|---|---|
| Benchmark_Memkey_Set-8 | 12,485,835 | 91.72 | 4 | 1 |
| Benchmark_Memkey_Get-8 | 30,052,064 | 39.77 | 0 | 0 |
| Benchmark_Memkey_SetAndDelete-8 | 6,038,889 | 194.4 | 4 | 1 |
If you encounter any issues or have suggestions for improvement, please open an issue on GitHub.
We welcome contributions! Fork the repository, make your changes, and submit a pull request.
If you enjoy using Memkey, please consider giving it a star! Your support helps others discover the project and encourages further development.
Memkey is open-source software released under the Apache License, Version 2.0. You can find a copy of the license in the LICENSE file.