Distributed data structures backed by Redis. Heavily inspired by Redisson.
The Mutex
struct aims to provide identical semantics to the sync.Mutex package.
ctx := context.Background()
client := redis.NewClient(&redis.Options{Addr: endpoint})
mutex := mutex.NewMutex(client, "test")
err := mutex.Lock(ctx)
err = mutex.Unlock(ctx)
The Map
struct aims to provide similar semantics to a native Go map.
ctx := context.Background()
client := redis.NewClient(&redis.Options{Addr: endpoint})
m := mapp.NewMap(client, "my-namespace")
err = m.Set(ctx, "key", "value")
value, exists, err := m.Get(ctx, "key")
The Map
struct supports generics so you can use any struct you'd like for the key/value. By default, structs will be
marshalled using json but can be configured with key/value marshalers.
m := mapp.NewMap(client, mapp.WithKeyMarshaler(...), mapp.WithValueMarshaller(...))