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_string_operation.go

40 lines
1017 B

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