Skip to content

Latest commit

 

History

History
42 lines (29 loc) · 1.46 KB

README.md

File metadata and controls

42 lines (29 loc) · 1.46 KB

go-redisson

Test GoDoc Go Report

Distributed data structures backed by Redis. Heavily inspired by Redisson.

Examples

Distributed Lock

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)

Distributed Map

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(...))