From 9807e8ed045e724ba7e922525a0c9d54a0654c47 Mon Sep 17 00:00:00 2001 From: Matrix-X Date: Thu, 2 Dec 2021 21:46:13 +0800 Subject: [PATCH] feat(redis): implement interface --- cache/redis.go | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/cache/redis.go b/cache/redis.go index 66cb691..15cd7c7 100644 --- a/cache/redis.go +++ b/cache/redis.go @@ -158,6 +158,11 @@ func (gr *GRedis) Add(key string, value interface{}, ttl time.Duration) (err err } +func (gr *GRedis) Set(key string, value interface{}, expires time.Duration) error { + result := gr.Pool.Set(CTXRedis, key, value, expires) + return result.Err() +} + func (gr *GRedis) SetEx(key string, value interface{}, expires time.Duration) error { mValue, err := json.Marshal(value) //mExpire, err := json.Marshal(expires) @@ -191,6 +196,15 @@ func (gr *GRedis) Get(key string, ptrValue interface{}) (returnValue interface{} return returnValue, err } +func (gr *GRedis) Has(key string) bool { + + value, err := gr.Get(key, nil) + if value != nil && err == nil { + return true + } + + return false +} func (gr *GRedis) GetMulti(keys ...string) (object.HashMap, error) { res, err := gr.Pool.MGet(CTXRedis, keys...).Result() @@ -254,7 +268,6 @@ func (gr *GRedis) Remember(key string, ttl time.Duration, callback func() interf return value, err } - /** * Store an item in the cache. *