1 Star 0 Fork 0

igo / pkg

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
redis_counter.go 607 Bytes
一键复制 编辑 原始数据 按行查看 历史
layte.xiao 提交于 2023-02-24 13:24 . redis支持keyPrefix
package xredis
import (
"context"
"fmt"
"time"
)
// RedisCounter Redis 计数器
type RedisCounter struct {
client *Client
key string
}
func NewRedisCounter(client *Client, key string, keyFmtArgs ...interface{}) *RedisCounter {
if len(keyFmtArgs) > 0 {
key = fmt.Sprintf(key, keyFmtArgs...)
}
return &RedisCounter{
client: client,
key: key,
}
}
func (c *RedisCounter) Incr(ctx context.Context) int64 {
return c.client.Incr(ctx, c.key).Val()
}
func (c *RedisCounter) Expire(ctx context.Context, duration time.Duration) error {
return c.client.Expire(ctx, c.key, duration).Err()
}
Go
1
https://gitee.com/igolang/pkg.git
git@gitee.com:igolang/pkg.git
igolang
pkg
pkg
v1.27.5

搜索帮助