- update redis
continuous-integration/drone/push Build is passing Details
continuous-integration/drone/tag Build is passing Details

master v1.0.15
李光春 2 years ago
parent 388310c804
commit c58e6fe761

@ -1,3 +1,3 @@
package dorm
const Version = "1.0.14"
const Version = "1.0.15"

@ -0,0 +1,73 @@
package dorm
import (
"context"
"github.com/go-redis/redis/v9"
"time"
)
// Set 设置一个key的值
func (c *RedisClient) Set(ctx context.Context, key string, value interface{}, expiration time.Duration) *redis.StatusCmd {
return c.Db.Set(ctx, key, value, expiration)
}
// Get 查询key的值
func (c *RedisClient) Get(ctx context.Context, key string) *redis.StringCmd {
return c.Db.Get(ctx, key)
}
// GetSet 设置一个key的值并返回这个key的旧值
func (c *RedisClient) GetSet(ctx context.Context, key string, value interface{}) *redis.StringCmd {
return c.Db.GetSet(ctx, key, value)
}
// SetNX 如果key不存在则设置这个key的值
func (c *RedisClient) SetNX(ctx context.Context, key string, value interface{}, expiration time.Duration) *redis.BoolCmd {
return c.Db.SetNX(ctx, key, value, expiration)
}
// MGet 批量查询key的值
func (c *RedisClient) MGet(ctx context.Context, keys ...string) *redis.SliceCmd {
return c.Db.MGet(ctx, keys...)
}
// MSet 批量设置key的值
// MSet(map[string]interface{}{"key1": "value1", "key2": "value2"})
func (c *RedisClient) MSet(ctx context.Context, values map[string]interface{}) *redis.StatusCmd {
return c.Db.MSet(ctx, values)
}
// Incr 针对一个key的数值进行递增操作
func (c *RedisClient) Incr(ctx context.Context, key string) *redis.IntCmd {
return c.Db.Incr(ctx, key)
}
// IncrBy 针对一个key的数值进行递增操作指定每次递增多少
func (c *RedisClient) IncrBy(ctx context.Context, key string, value int64) *redis.IntCmd {
return c.Db.IncrBy(ctx, key, value)
}
// Decr 针对一个key的数值进行递减操作
func (c *RedisClient) Decr(ctx context.Context, key string) *redis.IntCmd {
return c.Db.Decr(ctx, key)
}
// DecrBy 针对一个key的数值进行递减操作指定每次递减多少
func (c *RedisClient) DecrBy(ctx context.Context, key string, value int64) *redis.IntCmd {
return c.Db.DecrBy(ctx, key, value)
}
// Del 删除key操作支持批量删除
func (c *RedisClient) Del(ctx context.Context, keys ...string) *redis.IntCmd {
return c.Db.Del(ctx, keys...)
}
// Keys 按前缀获取所有 key
func (c *RedisClient) Keys(ctx context.Context, prefix string) *redis.SliceCmd {
values, _ := c.Db.Keys(ctx, prefix).Result()
keys := make([]string, 0, len(values))
for _, value := range values {
keys = append(keys, value)
}
return c.MGet(ctx, keys...)
}

@ -0,0 +1,31 @@
package dorm
import (
"context"
"github.com/go-redis/redis/v9"
)
// Subscribe 订阅channel
func (c *RedisClient) Subscribe(ctx context.Context, channels ...string) *redis.PubSub {
return c.Db.Subscribe(ctx, channels...)
}
// PSubscribe 订阅channel支持通配符匹配
func (c *RedisClient) PSubscribe(ctx context.Context, channels ...string) *redis.PubSub {
return c.Db.PSubscribe(ctx, channels...)
}
// Publish 将信息发送到指定的channel
func (c *RedisClient) Publish(ctx context.Context, channel string, message interface{}) *redis.IntCmd {
return c.Db.Publish(ctx, channel, message)
}
// PubSubChannels 查询活跃的channel
func (c *RedisClient) PubSubChannels(ctx context.Context, pattern string) *redis.StringSliceCmd {
return c.Db.PubSubChannels(ctx, pattern)
}
// PubSubNumSub 查询指定的channel有多少个订阅者
func (c *RedisClient) PubSubNumSub(ctx context.Context, channels ...string) *redis.StringIntMapCmd {
return c.Db.PubSubNumSub(ctx, channels...)
}
Loading…
Cancel
Save