Skip to content

byterio/memkey

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

16 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Memkey

Go Version License GoDoc Go Report Card

Memkey is a fast, lightweight in-memory key-value store for Go.

Features

  • 🚀 Fast, lightweight in-memory key-value store.
  • ⏰ Optional TTL per key.
  • ✨ Background cleanup to remove expired keys.
  • 🔐 Concurrent-safe.

Installation

go get -u github.com/byterio/memkey

Usage

package 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")
    }
}

Benchmarks

Benchmark on an Intel Core i7-6700HQ CPU @ 2.60GHz:

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

Feedback and Contributions

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.

Support

If you enjoy using Memkey, please consider giving it a star! Your support helps others discover the project and encourages further development.

License

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.

Releases

No releases published

Packages

 
 
 

Languages