Documentation ¶
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type CCacheKvStore ¶
type CCacheKvStore[V any] struct { Cache *ccache.Cache }
func NewCCacheKvStore ¶
func NewCCacheKvStore[V any](cc *ccache.Cache) *CCacheKvStore[V]
func (*CCacheKvStore[V]) Del ¶
func (cc *CCacheKvStore[V]) Del(ctx context.Context, key string) error
type FreeCacheKvStore ¶
Example ¶
store := NewFreeCacheKvStore(freecache.NewCache(32), MsgPackEncoder[string]()) ctx := context.TODO() v, exist, err := store.Get(ctx, `name`) fmt.Println(v == ``, exist, err) err = store.Set(ctx, `name`, `alice`, time.Second) fmt.Println(err) v, exist, err = store.Get(ctx, `name`) fmt.Println(v, exist, err) time.Sleep(time.Second) v, exist, err = store.Get(ctx, `name`) fmt.Println(v == ``, exist, err)
Output: true false <nil> <nil> alice true <nil> true false <nil>
func NewFreeCacheKvStore ¶
func NewFreeCacheKvStore[V any](fc *freecache.Cache, enc Encoder[V]) *FreeCacheKvStore[V]
func (*FreeCacheKvStore[V]) Del ¶
func (fc *FreeCacheKvStore[V]) Del(ctx context.Context, key string) error
type KvItem ¶
type RedisKvStore ¶
Example ¶
db, mock := redismock.NewClientMock() store := NewRedisKvStore(db, JsonEncoder[string]()) ctx := context.TODO() mock.ExpectGet(`name`).RedisNil() v, exist, err := store.Get(ctx, `name`) fmt.Println(v == ``, exist, err) cmd1 := mock.ExpectSet(`name`, []byte(`"alice"`), time.Second) cmd1.SetVal("") cmd1.SetErr(nil) err = store.Set(ctx, `name`, `alice`, time.Second) fmt.Println(err) cmd2 := mock.ExpectGet(`name`) cmd2.SetVal(`"alice"`) cmd2.SetErr(nil) v, exist, err = store.Get(ctx, `name`) fmt.Println(v, exist, err) time.Sleep(time.Second) mock.ExpectGet(`name`).RedisNil() v, exist, err = store.Get(ctx, `name`) fmt.Println(v == ``, exist, err)
Output: true false <nil> <nil> alice true <nil> true false <nil>
func NewRedisKvStore ¶
func NewRedisKvStore[V any](c *redis.Client, enc Encoder[V]) *RedisKvStore[V]
Click to show internal directories.
Click to hide internal directories.