Collection of key-value storages adapters for Golang
This project is maintained by reddec
github.com/reddec/storages/std/redistorage
Wrapper around Redis hashmap where one storage is one hashmap.
Each namespace is each key supposing that the value is hashmap.
Closing root (parent) storage will close all namespaced storages but not vice-versa.
Do not forget to import package!
redis://[[user][:<password>]@]<host>[:port][/<dbnum>][?key=<key>]
Where:
<user>
- optional user name for authorization<password>
- optional password for authorization<host>
- required address of redis database<port>
- optional (default 6379) database port<dbnum>
- optional (default 0) database num<key>
- optional (default DEFAULT
) name of hashmap to store dataExample:
redis://localhost
- simple, without authorization, on local hostredis://user:qwerty@localhost:8899/1?key=data
- with authorization, on localhost with custom port and custom database with hashmap key data
With new connection
storage, err := New("my-space", "redis://redishost")
if err != nil {
panic(err)
}
defer storage.Close()
or with helper that will panic on error
storage := MustNew("my-space", "redis://redishost")
defer storage.Close()
Wrap connection
storage := NewClient("my-space", redisConnection)
defer storage.Close()
Support NamespacedStorage interface.
It allows make nested sub-storages with independent key space.
Example:
aliceStorage := storage.Namespace([]byte("alice"))
bobStorage := storage.Namespace([]byte("bob"))