Remo is a Go package that provides in-memory key-value storage with expiration capabilities. It is designed to be a simple and efficient way to manage data with an optional time-to-live duration for keys.
- In-memory key-value storage with optional TTL (time-to-live).
- Thread-safe operations with efficient read and write locking.
- Automatic cleanup of expired keys.
- Simple and straightforward API.
You can install Remo using the Go module system:
go get github.com/itpey/remo
To get started, create a new instance of the Storage struct:
store := remo.New()
You can use the Set
and Get
methods to store and retrieve key-value pairs, with the option to set a time-to-live (TTL) duration for keys.
To set a key with no expiration, simply pass a TTL of 0:
// Set a key with a value and no expiration
store.Set("myKey", "myValue", 0)
You can also set a key with a specific TTL duration, which represents the time the key will be retained in the storage. For example, to set a key that expires in 30 minutes:
// Set a key with a value and a 30-minute TTL
store.Set("myKey", "myValue", 30 * time.Minute)
To retrieve a value by key, use the Get
method. It returns the value associated with the key and an error if the key does not exist or has expired:
value, err := store.Get("myKey")
if err != nil {
// Handle error (e.g., key not found or key has expired)
} else {
// Use the retrieved value
}
You can delete keys using the Delete
method:
store.Delete("myKey")
Remo includes an automatic cleanup feature that removes expired keys at a specified interval. You can start and stop this feature using the following methods:
// Start automatic cleanup (e.g., every 10 minutes)
store.StartCleanup(10 * time.Minute)
// Stop automatic cleanup
store.StopCleanup()
Remo provides a convenient Reset
method that allows you to clear all keys from the storage. This is useful when you need to start with an empty key-value store. Here's how to use the Reset
method:
store.Reset()
To run tests for Remo, use the following command:
go test github.com/itpey/remo
To run benchmarks for Remo, use the following command:
go test -bench=. github.com/itpey/remo
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.
Remo is open-source software released under the Apache License, Version 2.0. You can find a copy of the license in the LICENSE file.
Chunker was created by itpey