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.
dorm/redis_simple_operation.go

35 lines
853 B

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