Collection of key-value storages adapters for Golang
This project is maintained by reddec
Different implementations of storages with same abstract interface:
// Thread-safe storage for key-value
type Storage interface {
// Put single item to storage. If already exists - override
Put(key []byte, data []byte) error
// Get item from storage. If not exists - os.ErrNotExist (implementation independent)
Get(key []byte) ([]byte, error)
// Delete key and value
Del(key []byte) error
// Iterate over all keys. Modification during iteration may cause undefined behaviour (mostly - dead-lock)
Keys(handler func(key []byte) error) error
// Close storage if needs
io.Closer
}
static backend
func run() {
storage := memstorage.New()
storage.Put([]byte("alice"), []byte("data"))
restored, _ := storage.Get([]byte("alice"))
fmt.Println("Restored:", string(restored))
}
Due to standardized interface you may use
dynamic backend selection
(error handling omitted)
func run(backendURL string) {
storage, _ := std.Create(backendURL)
defer storage.Close()
storage.Put([]byte("alice"), []byte("data"))
restored, _ := storage.Get([]byte("alice"))
fmt.Println("Restored:", string(restored))
}
Table of all supported backends and their features.
Backend | Description | batch_writer | clearable | namespace |
---|---|---|---|---|
BBolt | Single-file, embeddable, pure-Go storage | ✔ | ||
Filesystem | Local file-system storage | ✔ | ||
LevelDB | Multi-files, embeddable, pure-Go storage | ✔ | ||
In-Memory | HashMap-based in-memory storage | ✔ | ✔ | ✔ |
Mock | Mocking storage that do nothing | ✔ | ||
Redis | Redis hashmap as a storage | ✔ | ||
REST | REST-like storage with server handler | |||
S3 | S3 capable buckets as a storage |
The wrappers itself licensed under MIT but used libraries may have different license politics.