You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
go-library/utils/dorm/redis_simple_operation.go

35 lines
853 B

2 years ago
package dorm
import (
"context"
1 year ago
"github.com/redis/go-redis/v9"
"time"
)
type SimpleOperation struct {
1 year ago
db *redis.Client
}
2 years ago
func (r *RedisClient) NewSimpleOperation() *SimpleOperation {
1 year ago
return &SimpleOperation{db: r.db}
}
// Set 设置
1 year ago
func (o *SimpleOperation) Set(ctx context.Context, key string, value interface{}, attrs ...*OperationAttr) *SimpleResult {
exp := OperationAttrs(attrs).Find(AttrExpr)
if exp == nil {
exp = time.Second * 0
}
1 year ago
return NewSimpleResult(o.db.Set(ctx, key, value, exp.(time.Duration)).Result())
}
// Get 获取单个
1 year ago
func (o *SimpleOperation) Get(ctx context.Context, key string) *SimpleResult {
return NewSimpleResult(o.db.Get(ctx, key).Result())
}
// Del 删除key操作支持批量删除
1 year ago
func (o *SimpleOperation) Del(ctx context.Context, keys ...string) *redis.IntCmd {
return o.db.Del(ctx, keys...)
}