Commit c9dceefb authored by chenweijian's avatar chenweijian

黄钻买粉钻

parent 3f915cc5
...@@ -74,3 +74,26 @@ func DelCache(key string) error { ...@@ -74,3 +74,26 @@ func DelCache(key string) error {
} }
return nil return nil
} }
func DecrBy(key string, num int64) (int64, error) {
resNum, err := RedisClient.DecrBy(context.Background(), key, num).Result()
if err != nil {
return 0, err
}
return resNum, nil
}
func DecrNumExpire(key string, num int64, expiration time.Duration) (int64, error) {
times, err := DecrBy(key, num)
if err != nil {
return 0, err
}
ttl, err := RedisClient.TTL(context.Background(), key).Result()
if err != nil {
return 0, err
}
if ttl == -1 {
RedisClient.Expire(context.Background(), key, expiration)
}
return times, nil
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment