Go访问Redis代码封装

这篇具有很好参考价值的文章主要介绍了Go访问Redis代码封装。希望对大家有所帮助。如果存在错误或未考虑完全的地方,请大家不吝赐教,您也可以点击"举报违法"按钮提交疑问。

1、Go的Redis客户端库

GO中可用于访问Redis的依赖包有下边4个:

  • https://github.com/gomodule/redigo
  • https://github.com/go-redis/redis
  • https://github.com/bsm/redeo
  • https://github.com/shomali11/xredis

其中go-redishttps://redis.uptrace.dev/zh/是与Redis官方有合作的,在Github的收藏数量也是最多,本文使用go-redis。
go-redis中文教程:https://redis.uptrace.dev/zh/guide/

2、工具类实现代码

安装 go-redis/v9 (支持所有的 redis 版本):

go get github.com/redis/go-redis/v9

go-redis 提供各种类型的客户端:

  • Redis 单节点客户端
  • Redis 集群客户端
  • Redis 哨兵客户端
  • Redis 分片客户端
  • Redis 通用客户端

本文只使用单节点客户端示例,封装了部分方法,其它方法可参考redis.Client添加。
redis-util.go

package goredis

// 

import (
	"context"
	"fmt"
	"github.com/redis/go-redis/v9"
	"time"
)

type RedisUtil struct {
	ctx context.Context
	db  *redis.Client
}

func (redisUtil *RedisUtil) Connect(url string, password string) {
	redisUtil.ctx = context.Background()
	redisUtil.db = redis.NewClient(&redis.Options{
		Addr:     url,
		Password: password,
		DB:       0,
	})
}

func (redisUtil *RedisUtil) Set(key string, value string, expiration time.Duration) error {
	err := redisUtil.db.Set(redisUtil.ctx, key, value, expiration).Err()
	if err != nil {
		panic(err)
	}
	return err
}

// 通过key获取值
// err == redis.Nil, "key不存在"
// err != nil,  "错误"
// val == "", "值是空字符串"
func (redisUtil *RedisUtil) Get(key string) (string, error) {
	value, err := redisUtil.db.Get(redisUtil.ctx, key).Result()
	if err != nil && value != "" {
		panic(err)
	}
	return value, err
}

// 删除key
func (redisUtil *RedisUtil) Del(keys ...string) error {
	err := redisUtil.db.Del(redisUtil.ctx, keys...).Err()
	if err != nil {
		panic(err)
	}
	return err
}

// 指定key的值+1
func (redisUtil *RedisUtil) Incr(key string) error {
	err := redisUtil.db.Incr(redisUtil.ctx, key).Err()
	if err != nil {
		panic(err)
	}
	return err
}

// 指定key的值+1
func (redisUtil *RedisUtil) Decr(key string) error {
	err := redisUtil.db.Decr(redisUtil.ctx, key).Err()
	if err != nil {
		panic(err)
	}
	return err
}

// 批量设置,没有过期时间
func (redisUtil *RedisUtil) MSet(values ...interface{}) error {
	err := redisUtil.db.MSet(redisUtil.ctx, values...).Err()
	return err
}

// 批量设置取数据
// 示例:values, err := MGet(key1, key2)
// for i, _ := range values {
// fmt.Println(values[i])
// }
func (redisUtil *RedisUtil) MGet(keys ...string) ([]interface{}, error) {
	values, err := redisUtil.db.MGet(redisUtil.ctx, keys...).Result()
	return values, err
}

// 执行命令
// 返回结果
// s, err := cmd.Text()
// flag, err := cmd.Bool()
// num, err := cmd.Int()
// num, err := cmd.Int64()
// num, err := cmd.Uint64()
// num, err := cmd.Float32()
// num, err := cmd.Float64()
// ss, err := cmd.StringSlice()
// ns, err := cmd.Int64Slice()
// ns, err := cmd.Uint64Slice()
// fs, err := cmd.Float32Slice()
// fs, err := cmd.Float64Slice()
// bs, err := cmd.BoolSlice()
func (redisUtil *RedisUtil) Do(args ...interface{}) *redis.Cmd {
	cmd := redisUtil.db.Do(redisUtil.ctx, args)
	return cmd
}

// 清空缓存
func (redisUtil *RedisUtil) FlushDB() error {
	err := redisUtil.db.FlushDB(redisUtil.ctx).Err()
	return err
}

// 发布
// 示例Publish("mychannel1", "payload").Err()
func (redisUtil *RedisUtil) Publish(channel string, msg string) error {
	err := redisUtil.db.Publish(redisUtil.ctx, channel, msg).Err()
	return err
}

// 订阅
func (redisUtil *RedisUtil) Subscribe(channel string, subscribe func(msg *redis.Message, err error)) {
	pubsub := redisUtil.db.Subscribe(redisUtil.ctx, channel)
	// 使用完毕,记得关闭
	defer pubsub.Close()
	for {
		msg, err := pubsub.ReceiveMessage(redisUtil.ctx)
		subscribe(msg, err)
	}
}

// 列表的头部(左边),尾部(右边)
// 列表左边插入
func (redisUtil *RedisUtil) LPust(channel string, values ...interface{}) error {
	return redisUtil.db.LPush(redisUtil.ctx, channel, values...).Err()
}

// 列表从左边开始取出start至stop位置的数据
func (redisUtil *RedisUtil) LRange(key string, start, stop int64) error {
	return redisUtil.db.LRange(redisUtil.ctx, key, start, stop).Err()
}

// 列表左边取出
func (redisUtil *RedisUtil) LPop(key string) *redis.StringCmd {
	return redisUtil.db.LPop(redisUtil.ctx, key)
}

// 列表右边插入
func (redisUtil *RedisUtil) RPust(channel string, values ...interface{}) error {
	return redisUtil.db.RPush(redisUtil.ctx, channel, values...).Err()
}

// 列表右边取出
func (redisUtil *RedisUtil) RPop(key string) error {
	return redisUtil.db.RPop(redisUtil.ctx, key).Err()
}

// 列表哈希插入
func (redisUtil *RedisUtil) HSet(key string, values ...interface{}) error {
	return redisUtil.db.HSet(redisUtil.ctx, key, values...).Err()
}

// 列表哈希取出
func (redisUtil *RedisUtil) HGet(key, field string) *redis.StringCmd {
	return redisUtil.db.HGet(redisUtil.ctx, key, field)
}

// 列表哈希批量插入
func (redisUtil *RedisUtil) HMSet(key string, values ...interface{}) error {
	return redisUtil.db.HMSet(redisUtil.ctx, key, values...).Err()
}

// 列表哈希批量取出
func (redisUtil *RedisUtil) HMGet(key string, fields ...string) []interface{} {
	return redisUtil.db.HMGet(redisUtil.ctx, key, fields...).Val()
}

// 列表无序集合插入
func (redisUtil *RedisUtil) SAdd(key string, members ...interface{}) error {
	return redisUtil.db.SAdd(redisUtil.ctx, key, members...).Err()
}

// 列表无序集合,返回所有元素
func (redisUtil *RedisUtil) SMembers(key string) []string {
	return redisUtil.db.SMembers(redisUtil.ctx, key).Val()
}

// 列表无序集合,检查元素是否存在
func (redisUtil *RedisUtil) SIsMember(key string, member interface{}) bool {
	b, err := redisUtil.db.SIsMember(redisUtil.ctx, key, member).Result()
	if err != nil {
		panic(err)
	}
	return b
}

使用例子文章来源地址https://www.toymoban.com/news/detail-656006.html

package main

import (
	"fmt"
	"github.com/redis/go-redis/v9"
	"myredis/pkg/goredis"
	"strconv"
	"time"
)

func main() {

	redisUtil := goredis.RedisUtil{}
	url := "localhost:6379"
	password := ""
	redisUtil.Connect(url, password)
	key1 := "test2"
	redisUtil.Set(key1, "mydata", 0)
	value1, _ := redisUtil.Get(key1)
	fmt.Printf("get:%v\n", value1)
	//删除
	redisUtil.Del(key1)
	value2, _ := redisUtil.Get(key1)
	fmt.Printf("FlushDB get:%v\n", value2)
	// 加1
	redisUtil.Incr(key1)
	value3, _ := redisUtil.Get(key1)
	fmt.Printf("Incr get:%v\n", value3)

	// 发布订阅
	key2 := "mychannel"

	go redisUtil.Subscribe(key2, func(msg *redis.Message, err error) {
		if err != nil {
			panic(err)
		}
		fmt.Println("Subscribe===", msg.Channel, msg.Payload)
	})
	time.Sleep(time.Second * 1)
	go func() {
		for i := 0; i < 5; i++ {
			redisUtil.Publish(key2, "aaaa:"+strconv.Itoa(i))
			time.Sleep(time.Millisecond * 100)
		}
	}()
	time.Sleep(time.Second * 1)
}

3、redis.Client类型包含的方法

  • func NewClient(opt *Options) *Client
  • func NewFailoverClient(failoverOpt *FailoverOptions) *Client
  • func (c Client) ACLDryRun(ctx context.Context, username string, command …interface{}) *StringCmd
  • func (c Client) ACLLog(ctx context.Context, count int64) *ACLLogCmd
  • func (c Client) ACLLogReset(ctx context.Context) *StatusCmd
  • func (hs *Client) AddHook(hook Hook)
  • func (c Client) Append(ctx context.Context, key, value string) *IntCmd
  • func (c Client) BLMPop(ctx context.Context, timeout time.Duration, direction string, count int64, …) *KeyValuesCmd
  • func (c Client) BLMove(ctx context.Context, source, destination, srcpos, destpos string, …) *StringCmd
  • func (c Client) BLPop(ctx context.Context, timeout time.Duration, keys …string) *StringSliceCmd
  • func (c Client) BRPop(ctx context.Context, timeout time.Duration, keys …string) *StringSliceCmd
  • func (c Client) BRPopLPush(ctx context.Context, source, destination string, timeout time.Duration) *StringCmd
  • func (c Client) BZMPop(ctx context.Context, timeout time.Duration, order string, count int64, …) *ZSliceWithKeyCmd
  • func (c Client) BZPopMax(ctx context.Context, timeout time.Duration, keys …string) *ZWithKeyCmd
  • func (c Client) BZPopMin(ctx context.Context, timeout time.Duration, keys …string) *ZWithKeyCmd
  • func (c Client) BgRewriteAOF(ctx context.Context) *StatusCmd
  • func (c Client) BgSave(ctx context.Context) *StatusCmd
  • func (c Client) BitCount(ctx context.Context, key string, bitCount *BitCount) *IntCmd
  • func (c Client) BitField(ctx context.Context, key string, args …interface{}) *IntSliceCmd
  • func (c Client) BitOpAnd(ctx context.Context, destKey string, keys …string) *IntCmd
  • func (c Client) BitOpNot(ctx context.Context, destKey string, key string) *IntCmd
  • func (c Client) BitOpOr(ctx context.Context, destKey string, keys …string) *IntCmd
  • func (c Client) BitOpXor(ctx context.Context, destKey string, keys …string) *IntCmd
  • func (c Client) BitPos(ctx context.Context, key string, bit int64, pos …int64) *IntCmd
  • func (c Client) BitPosSpan(ctx context.Context, key string, bit int8, start, end int64, span string) *IntCmd
  • func (c Client) ClientGetName(ctx context.Context) *StringCmd
  • func (c Client) ClientID(ctx context.Context) *IntCmd
  • func (c Client) ClientInfo(ctx context.Context) *ClientInfoCmd
  • func (c Client) ClientKill(ctx context.Context, ipPort string) *StatusCmd
  • func (c Client) ClientKillByFilter(ctx context.Context, keys …string) *IntCmd
  • func (c Client) ClientList(ctx context.Context) *StringCmd
  • func (c Client) ClientPause(ctx context.Context, dur time.Duration) *BoolCmd
  • func (c Client) ClientUnblock(ctx context.Context, id int64) *IntCmd
  • func (c Client) ClientUnblockWithError(ctx context.Context, id int64) *IntCmd
  • func (c Client) ClientUnpause(ctx context.Context) *BoolCmd
  • func (c Client) Close() error
  • func (c Client) ClusterAddSlots(ctx context.Context, slots …int) *StatusCmd
  • func (c Client) ClusterAddSlotsRange(ctx context.Context, min, max int) *StatusCmd
  • func (c Client) ClusterCountFailureReports(ctx context.Context, nodeID string) *IntCmd
  • func (c Client) ClusterCountKeysInSlot(ctx context.Context, slot int) *IntCmd
  • func (c Client) ClusterDelSlots(ctx context.Context, slots …int) *StatusCmd
  • func (c Client) ClusterDelSlotsRange(ctx context.Context, min, max int) *StatusCmd
  • func (c Client) ClusterFailover(ctx context.Context) *StatusCmd
  • func (c Client) ClusterForget(ctx context.Context, nodeID string) *StatusCmd
  • func (c Client) ClusterGetKeysInSlot(ctx context.Context, slot int, count int) *StringSliceCmd
  • func (c Client) ClusterInfo(ctx context.Context) *StringCmd
  • func (c Client) ClusterKeySlot(ctx context.Context, key string) *IntCmd
  • func (c Client) ClusterLinks(ctx context.Context) *ClusterLinksCmd
  • func (c Client) ClusterMeet(ctx context.Context, host, port string) *StatusCmd
  • func (c Client) ClusterMyShardID(ctx context.Context) *StringCmd
  • func (c Client) ClusterNodes(ctx context.Context) *StringCmd
  • func (c Client) ClusterReplicate(ctx context.Context, nodeID string) *StatusCmd
  • func (c Client) ClusterResetHard(ctx context.Context) *StatusCmd
  • func (c Client) ClusterResetSoft(ctx context.Context) *StatusCmd
  • func (c Client) ClusterSaveConfig(ctx context.Context) *StatusCmd
  • func (c Client) ClusterShards(ctx context.Context) *ClusterShardsCmd
  • func (c Client) ClusterSlaves(ctx context.Context, nodeID string) *StringSliceCmd
  • func (c Client) ClusterSlots(ctx context.Context) *ClusterSlotsCmd
  • func (c Client) Command(ctx context.Context) *CommandsInfoCmd
  • func (c Client) CommandGetKeys(ctx context.Context, commands …interface{}) *StringSliceCmd
  • func (c Client) CommandGetKeysAndFlags(ctx context.Context, commands …interface{}) *KeyFlagsCmd
  • func (c Client) CommandList(ctx context.Context, filter *FilterBy) *StringSliceCmd
  • func (c Client) ConfigGet(ctx context.Context, parameter string) *MapStringStringCmd
  • func (c Client) ConfigResetStat(ctx context.Context) *StatusCmd
  • func (c Client) ConfigRewrite(ctx context.Context) *StatusCmd
  • func (c Client) ConfigSet(ctx context.Context, parameter, value string) *StatusCmd
  • func (c *Client) Conn() *Conn
  • func (c Client) Copy(ctx context.Context, sourceKey, destKey string, db int, replace bool) *IntCmd
  • func (c Client) DBSize(ctx context.Context) *IntCmd
  • func (c Client) DebugObject(ctx context.Context, key string) *StringCmd
  • func (c Client) Decr(ctx context.Context, key string) *IntCmd
  • func (c Client) DecrBy(ctx context.Context, key string, decrement int64) *IntCmd
  • func (c Client) Del(ctx context.Context, keys …string) *IntCmd
  • func (c *Client) Do(ctx context.Context, args …interface{}) *Cmd
  • func (c Client) Dump(ctx context.Context, key string) *StringCmd
  • func (c Client) Echo(ctx context.Context, message interface{}) *StringCmd
  • func (c Client) Eval(ctx context.Context, script string, keys []string, args …interface{}) *Cmd
  • func (c Client) EvalRO(ctx context.Context, script string, keys []string, args …interface{}) *Cmd
  • func (c Client) EvalSha(ctx context.Context, sha1 string, keys []string, args …interface{}) *Cmd
  • func (c Client) EvalShaRO(ctx context.Context, sha1 string, keys []string, args …interface{}) *Cmd
  • func (c Client) Exists(ctx context.Context, keys …string) *IntCmd
  • func (c Client) Expire(ctx context.Context, key string, expiration time.Duration) *BoolCmd
  • func (c Client) ExpireAt(ctx context.Context, key string, tm time.Time) *BoolCmd
  • func (c Client) ExpireGT(ctx context.Context, key string, expiration time.Duration) *BoolCmd
  • func (c Client) ExpireLT(ctx context.Context, key string, expiration time.Duration) *BoolCmd
  • func (c Client) ExpireNX(ctx context.Context, key string, expiration time.Duration) *BoolCmd
  • func (c Client) ExpireTime(ctx context.Context, key string) *DurationCmd
  • func (c Client) ExpireXX(ctx context.Context, key string, expiration time.Duration) *BoolCmd
  • func (c Client) FCall(ctx context.Context, function string, keys []string, args …interface{}) *Cmd
  • func (c Client) FCallRO(ctx context.Context, function string, keys []string, args …interface{}) *Cmd
  • func (c Client) FCallRo(ctx context.Context, function string, keys []string, args …interface{}) *Cmd
  • func (c Client) FlushAll(ctx context.Context) *StatusCmd
  • func (c Client) FlushAllAsync(ctx context.Context) *StatusCmd
  • func (c Client) FlushDB(ctx context.Context) *StatusCmd
  • func (c Client) FlushDBAsync(ctx context.Context) *StatusCmd
  • func (c Client) FunctionDelete(ctx context.Context, libName string) *StringCmd
  • func (c Client) FunctionDump(ctx context.Context) *StringCmd
  • func (c Client) FunctionFlush(ctx context.Context) *StringCmd
  • func (c Client) FunctionFlushAsync(ctx context.Context) *StringCmd
  • func (c Client) FunctionKill(ctx context.Context) *StringCmd
  • func (c Client) FunctionList(ctx context.Context, q FunctionListQuery) *FunctionListCmd
  • func (c Client) FunctionLoad(ctx context.Context, code string) *StringCmd
  • func (c Client) FunctionLoadReplace(ctx context.Context, code string) *StringCmd
  • func (c Client) FunctionRestore(ctx context.Context, libDump string) *StringCmd
  • func (c Client) FunctionStats(ctx context.Context) *FunctionStatsCmd
  • func (c Client) GeoAdd(ctx context.Context, key string, geoLocation …*GeoLocation) *IntCmd
  • func (c Client) GeoDist(ctx context.Context, key string, member1, member2, unit string) *FloatCmd
  • func (c Client) GeoHash(ctx context.Context, key string, members …string) *StringSliceCmd
  • func (c Client) GeoPos(ctx context.Context, key string, members …string) *GeoPosCmd
  • func (c Client) GeoRadius(ctx context.Context, key string, longitude, latitude float64, …) *GeoLocationCmd
  • func (c Client) GeoRadiusByMember(ctx context.Context, key, member string, query *GeoRadiusQuery) *GeoLocationCmd
  • func (c Client) GeoRadiusByMemberStore(ctx context.Context, key, member string, query *GeoRadiusQuery) *IntCmd
  • func (c Client) GeoRadiusStore(ctx context.Context, key string, longitude, latitude float64, …) *IntCmd
  • func (c Client) GeoSearch(ctx context.Context, key string, q *GeoSearchQuery) *StringSliceCmd
  • func (c Client) GeoSearchLocation(ctx context.Context, key string, q *GeoSearchLocationQuery) *GeoSearchLocationCmd
  • func (c Client) GeoSearchStore(ctx context.Context, key, store string, q *GeoSearchStoreQuery) *IntCmd
  • func (c Client) Get(ctx context.Context, key string) *StringCmd
  • func (c Client) GetBit(ctx context.Context, key string, offset int64) *IntCmd
  • func (c Client) GetDel(ctx context.Context, key string) *StringCmd
  • func (c Client) GetEx(ctx context.Context, key string, expiration time.Duration) *StringCmd
  • func (c Client) GetRange(ctx context.Context, key string, start, end int64) *StringCmd
  • func (c Client) GetSet(ctx context.Context, key string, value interface{}) *StringCmd
  • func (c Client) HDel(ctx context.Context, key string, fields …string) *IntCmd
  • func (c Client) HExists(ctx context.Context, key, field string) *BoolCmd
  • func (c Client) HGet(ctx context.Context, key, field string) *StringCmd
  • func (c Client) HGetAll(ctx context.Context, key string) *MapStringStringCmd
  • func (c Client) HIncrBy(ctx context.Context, key, field string, incr int64) *IntCmd
  • func (c Client) HIncrByFloat(ctx context.Context, key, field string, incr float64) *FloatCmd
  • func (c Client) HKeys(ctx context.Context, key string) *StringSliceCmd
  • func (c Client) HLen(ctx context.Context, key string) *IntCmd
  • func (c Client) HMGet(ctx context.Context, key string, fields …string) *SliceCmd
  • func (c Client) HMSet(ctx context.Context, key string, values …interface{}) *BoolCmd
  • func (c Client) HRandField(ctx context.Context, key string, count int) *StringSliceCmd
  • func (c Client) HRandFieldWithValues(ctx context.Context, key string, count int) *KeyValueSliceCmd
  • func (c Client) HScan(ctx context.Context, key string, cursor uint64, match string, count int64) *ScanCmd
  • func (c Client) HSet(ctx context.Context, key string, values …interface{}) *IntCmd
  • func (c Client) HSetNX(ctx context.Context, key, field string, value interface{}) *BoolCmd
  • func (c Client) HVals(ctx context.Context, key string) *StringSliceCmd
  • func (c Client) Incr(ctx context.Context, key string) *IntCmd
  • func (c Client) IncrBy(ctx context.Context, key string, value int64) *IntCmd
  • func (c Client) IncrByFloat(ctx context.Context, key string, value float64) *FloatCmd
  • func (c Client) Info(ctx context.Context, sections …string) *StringCmd
  • func (c Client) Keys(ctx context.Context, pattern string) *StringSliceCmd
  • func (c Client) LCS(ctx context.Context, q *LCSQuery) *LCSCmd
  • func (c Client) LIndex(ctx context.Context, key string, index int64) *StringCmd
  • func (c Client) LInsert(ctx context.Context, key, op string, pivot, value interface{}) *IntCmd
  • func (c Client) LInsertAfter(ctx context.Context, key string, pivot, value interface{}) *IntCmd
  • func (c Client) LInsertBefore(ctx context.Context, key string, pivot, value interface{}) *IntCmd
  • func (c Client) LLen(ctx context.Context, key string) *IntCmd
  • func (c Client) LMPop(ctx context.Context, direction string, count int64, keys …string) *KeyValuesCmd
  • func (c Client) LMove(ctx context.Context, source, destination, srcpos, destpos string) *StringCmd
  • func (c Client) LPop(ctx context.Context, key string) *StringCmd
  • func (c Client) LPopCount(ctx context.Context, key string, count int) *StringSliceCmd
  • func (c Client) LPos(ctx context.Context, key string, value string, a LPosArgs) *IntCmd
  • func (c Client) LPosCount(ctx context.Context, key string, value string, count int64, a LPosArgs) *IntSliceCmd
  • func (c Client) LPush(ctx context.Context, key string, values …interface{}) *IntCmd
  • func (c Client) LPushX(ctx context.Context, key string, values …interface{}) *IntCmd
  • func (c Client) LRange(ctx context.Context, key string, start, stop int64) *StringSliceCmd
  • func (c Client) LRem(ctx context.Context, key string, count int64, value interface{}) *IntCmd
  • func (c Client) LSet(ctx context.Context, key string, index int64, value interface{}) *StatusCmd
  • func (c Client) LTrim(ctx context.Context, key string, start, stop int64) *StatusCmd
  • func (c Client) LastSave(ctx context.Context) *IntCmd
  • func (c Client) MGet(ctx context.Context, keys …string) *SliceCmd
  • func (c Client) MSet(ctx context.Context, values …interface{}) *StatusCmd
  • func (c Client) MSetNX(ctx context.Context, values …interface{}) *BoolCmd
  • func (c Client) MemoryUsage(ctx context.Context, key string, samples …int) *IntCmd
  • func (c Client) Migrate(ctx context.Context, host, port, key string, db int, timeout time.Duration) *StatusCmd
  • func (c Client) ModuleLoadex(ctx context.Context, conf *ModuleLoadexConfig) *StringCmd
  • func (c Client) Move(ctx context.Context, key string, db int) *BoolCmd
  • func (c Client) ObjectEncoding(ctx context.Context, key string) *StringCmd
  • func (c Client) ObjectIdleTime(ctx context.Context, key string) *DurationCmd
  • func (c Client) ObjectRefCount(ctx context.Context, key string) *IntCmd
  • func (c *Client) Options() *Options
  • func (c Client) PExpire(ctx context.Context, key string, expiration time.Duration) *BoolCmd
  • func (c Client) PExpireAt(ctx context.Context, key string, tm time.Time) *BoolCmd
  • func (c Client) PExpireTime(ctx context.Context, key string) *DurationCmd
  • func (c Client) PFAdd(ctx context.Context, key string, els …interface{}) *IntCmd
  • func (c Client) PFCount(ctx context.Context, keys …string) *IntCmd
  • func (c Client) PFMerge(ctx context.Context, dest string, keys …string) *StatusCmd
  • func (c *Client) PSubscribe(ctx context.Context, channels …string) *PubSub
  • func (c Client) PTTL(ctx context.Context, key string) *DurationCmd
  • func (c Client) Persist(ctx context.Context, key string) *BoolCmd
  • func (c Client) Ping(ctx context.Context) *StatusCmd
  • func (c *Client) Pipeline() Pipeliner
  • func (c *Client) Pipelined(ctx context.Context, fn func(Pipeliner) error) ([]Cmder, error)
  • func (c *Client) PoolStats() *PoolStats
  • func (c *Client) Process(ctx context.Context, cmd Cmder) error
  • func (c Client) PubSubChannels(ctx context.Context, pattern string) *StringSliceCmd
  • func (c Client) PubSubNumPat(ctx context.Context) *IntCmd
  • func (c Client) PubSubNumSub(ctx context.Context, channels …string) *MapStringIntCmd
  • func (c Client) PubSubShardChannels(ctx context.Context, pattern string) *StringSliceCmd
  • func (c Client) PubSubShardNumSub(ctx context.Context, channels …string) *MapStringIntCmd
  • func (c Client) Publish(ctx context.Context, channel string, message interface{}) *IntCmd
  • func (c Client) Quit(_ context.Context) *StatusCmd
  • func (c Client) RPop(ctx context.Context, key string) *StringCmd
  • func (c Client) RPopCount(ctx context.Context, key string, count int) *StringSliceCmd
  • func (c Client) RPopLPush(ctx context.Context, source, destination string) *StringCmd
  • func (c Client) RPush(ctx context.Context, key string, values …interface{}) *IntCmd
  • func (c Client) RPushX(ctx context.Context, key string, values …interface{}) *IntCmd
  • func (c Client) RandomKey(ctx context.Context) *StringCmd
  • func (c Client) ReadOnly(ctx context.Context) *StatusCmd
  • func (c Client) ReadWrite(ctx context.Context) *StatusCmd
  • func (c Client) Rename(ctx context.Context, key, newkey string) *StatusCmd
  • func (c Client) RenameNX(ctx context.Context, key, newkey string) *BoolCmd
  • func (c Client) Restore(ctx context.Context, key string, ttl time.Duration, value string) *StatusCmd
  • func (c Client) RestoreReplace(ctx context.Context, key string, ttl time.Duration, value string) *StatusCmd
  • func (c Client) SAdd(ctx context.Context, key string, members …interface{}) *IntCmd
  • func (c Client) SCard(ctx context.Context, key string) *IntCmd
  • func (c Client) SDiff(ctx context.Context, keys …string) *StringSliceCmd
  • func (c Client) SDiffStore(ctx context.Context, destination string, keys …string) *IntCmd
  • func (c Client) SInter(ctx context.Context, keys …string) *StringSliceCmd
  • func (c Client) SInterCard(ctx context.Context, limit int64, keys …string) *IntCmd
  • func (c Client) SInterStore(ctx context.Context, destination string, keys …string) *IntCmd
  • func (c Client) SIsMember(ctx context.Context, key string, member interface{}) *BoolCmd
  • func (c Client) SMIsMember(ctx context.Context, key string, members …interface{}) *BoolSliceCmd
  • func (c Client) SMembers(ctx context.Context, key string) *StringSliceCmd
  • func (c Client) SMembersMap(ctx context.Context, key string) *StringStructMapCmd
  • func (c Client) SMove(ctx context.Context, source, destination string, member interface{}) *BoolCmd
  • func (c Client) SPop(ctx context.Context, key string) *StringCmd
  • func (c Client) SPopN(ctx context.Context, key string, count int64) *StringSliceCmd
  • func (c Client) SPublish(ctx context.Context, channel string, message interface{}) *IntCmd
  • func (c Client) SRandMember(ctx context.Context, key string) *StringCmd
  • func (c Client) SRandMemberN(ctx context.Context, key string, count int64) *StringSliceCmd
  • func (c Client) SRem(ctx context.Context, key string, members …interface{}) *IntCmd
  • func (c Client) SScan(ctx context.Context, key string, cursor uint64, match string, count int64) *ScanCmd
  • func (c *Client) SSubscribe(ctx context.Context, channels …string) *PubSub
  • func (c Client) SUnion(ctx context.Context, keys …string) *StringSliceCmd
  • func (c Client) SUnionStore(ctx context.Context, destination string, keys …string) *IntCmd
  • func (c Client) Save(ctx context.Context) *StatusCmd
  • func (c Client) Scan(ctx context.Context, cursor uint64, match string, count int64) *ScanCmd
  • func (c Client) ScanType(ctx context.Context, cursor uint64, match string, count int64, keyType string) *ScanCmd
  • func (c Client) ScriptExists(ctx context.Context, hashes …string) *BoolSliceCmd
  • func (c Client) ScriptFlush(ctx context.Context) *StatusCmd
  • func (c Client) ScriptKill(ctx context.Context) *StatusCmd
  • func (c Client) ScriptLoad(ctx context.Context, script string) *StringCmd
  • func (c Client) Set(ctx context.Context, key string, value interface{}, expiration time.Duration) *StatusCmd
  • func (c Client) SetArgs(ctx context.Context, key string, value interface{}, a SetArgs) *StatusCmd
  • func (c Client) SetBit(ctx context.Context, key string, offset int64, value int) *IntCmd
  • func (c Client) SetEx(ctx context.Context, key string, value interface{}, expiration time.Duration) *StatusCmd
  • func (c Client) SetNX(ctx context.Context, key string, value interface{}, expiration time.Duration) *BoolCmd
  • func (c Client) SetRange(ctx context.Context, key string, offset int64, value string) *IntCmd
  • func (c Client) SetXX(ctx context.Context, key string, value interface{}, expiration time.Duration) *BoolCmd
  • func (c Client) Shutdown(ctx context.Context) *StatusCmd
  • func (c Client) ShutdownNoSave(ctx context.Context) *StatusCmd
  • func (c Client) ShutdownSave(ctx context.Context) *StatusCmd
  • func (c Client) SlaveOf(ctx context.Context, host, port string) *StatusCmd
  • func (c Client) SlowLogGet(ctx context.Context, num int64) *SlowLogCmd
  • func (c Client) Sort(ctx context.Context, key string, sort *Sort) *StringSliceCmd
  • func (c Client) SortInterfaces(ctx context.Context, key string, sort *Sort) *SliceCmd
  • func (c Client) SortRO(ctx context.Context, key string, sort *Sort) *StringSliceCmd
  • func (c Client) SortStore(ctx context.Context, key, store string, sort *Sort) *IntCmd
  • func (c Client) StrLen(ctx context.Context, key string) *IntCmd
  • func (c Client) String() string
  • func (c *Client) Subscribe(ctx context.Context, channels …string) *PubSub
  • func (c Client) Sync(_ context.Context)
  • func (c Client) TTL(ctx context.Context, key string) *DurationCmd
  • func (c Client) Time(ctx context.Context) *TimeCmd
  • func (c Client) Touch(ctx context.Context, keys …string) *IntCmd
  • func (c *Client) TxPipeline() Pipeliner
  • func (c *Client) TxPipelined(ctx context.Context, fn func(Pipeliner) error) ([]Cmder, error)
  • func (c Client) Type(ctx context.Context, key string) *StatusCmd
  • func (c Client) Unlink(ctx context.Context, keys …string) *IntCmd
  • func (c Client) Wait(ctx context.Context, numSlaves int, timeout time.Duration) *IntCmd
  • func (c *Client) Watch(ctx context.Context, fn func(*Tx) error, keys …string) error
  • func (c *Client) WithTimeout(timeout time.Duration) *Client
  • func (c Client) XAck(ctx context.Context, stream, group string, ids …string) *IntCmd
  • func (c Client) XAdd(ctx context.Context, a *XAddArgs) *StringCmd
  • func (c Client) XAutoClaim(ctx context.Context, a *XAutoClaimArgs) *XAutoClaimCmd
  • func (c Client) XAutoClaimJustID(ctx context.Context, a *XAutoClaimArgs) *XAutoClaimJustIDCmd
  • func (c Client) XClaim(ctx context.Context, a *XClaimArgs) *XMessageSliceCmd
  • func (c Client) XClaimJustID(ctx context.Context, a *XClaimArgs) *StringSliceCmd
  • func (c Client) XDel(ctx context.Context, stream string, ids …string) *IntCmd
  • func (c Client) XGroupCreate(ctx context.Context, stream, group, start string) *StatusCmd
  • func (c Client) XGroupCreateConsumer(ctx context.Context, stream, group, consumer string) *IntCmd
  • func (c Client) XGroupCreateMkStream(ctx context.Context, stream, group, start string) *StatusCmd
  • func (c Client) XGroupDelConsumer(ctx context.Context, stream, group, consumer string) *IntCmd
  • func (c Client) XGroupDestroy(ctx context.Context, stream, group string) *IntCmd
  • func (c Client) XGroupSetID(ctx context.Context, stream, group, start string) *StatusCmd
  • func (c Client) XInfoConsumers(ctx context.Context, key string, group string) *XInfoConsumersCmd
  • func (c Client) XInfoGroups(ctx context.Context, key string) *XInfoGroupsCmd
  • func (c Client) XInfoStream(ctx context.Context, key string) *XInfoStreamCmd
  • func (c Client) XInfoStreamFull(ctx context.Context, key string, count int) *XInfoStreamFullCmd
  • func (c Client) XLen(ctx context.Context, stream string) *IntCmd
  • func (c Client) XPending(ctx context.Context, stream, group string) *XPendingCmd
  • func (c Client) XPendingExt(ctx context.Context, a *XPendingExtArgs) *XPendingExtCmd
  • func (c Client) XRange(ctx context.Context, stream, start, stop string) *XMessageSliceCmd
  • func (c Client) XRangeN(ctx context.Context, stream, start, stop string, count int64) *XMessageSliceCmd
  • func (c Client) XRead(ctx context.Context, a *XReadArgs) *XStreamSliceCmd
  • func (c Client) XReadGroup(ctx context.Context, a *XReadGroupArgs) *XStreamSliceCmd
  • func (c Client) XReadStreams(ctx context.Context, streams …string) *XStreamSliceCmd
  • func (c Client) XRevRange(ctx context.Context, stream, start, stop string) *XMessageSliceCmd
  • func (c Client) XRevRangeN(ctx context.Context, stream, start, stop string, count int64) *XMessageSliceCmd
  • func (c Client) XTrimMaxLen(ctx context.Context, key string, maxLen int64) *IntCmd
  • func (c Client) XTrimMaxLenApprox(ctx context.Context, key string, maxLen, limit int64) *IntCmd
  • func (c Client) XTrimMinID(ctx context.Context, key string, minID string) *IntCmd
  • func (c Client) XTrimMinIDApprox(ctx context.Context, key string, minID string, limit int64) *IntCmd
  • func (c Client) ZAdd(ctx context.Context, key string, members …Z) *IntCmd
  • func (c Client) ZAddArgs(ctx context.Context, key string, args ZAddArgs) *IntCmd
  • func (c Client) ZAddArgsIncr(ctx context.Context, key string, args ZAddArgs) *FloatCmd
  • func (c Client) ZAddGT(ctx context.Context, key string, members …Z) *IntCmd
  • func (c Client) ZAddLT(ctx context.Context, key string, members …Z) *IntCmd
  • func (c Client) ZAddNX(ctx context.Context, key string, members …Z) *IntCmd
  • func (c Client) ZAddXX(ctx context.Context, key string, members …Z) *IntCmd
  • func (c Client) ZCard(ctx context.Context, key string) *IntCmd
  • func (c Client) ZCount(ctx context.Context, key, min, max string) *IntCmd
  • func (c Client) ZDiff(ctx context.Context, keys …string) *StringSliceCmd
  • func (c Client) ZDiffStore(ctx context.Context, destination string, keys …string) *IntCmd
  • func (c Client) ZDiffWithScores(ctx context.Context, keys …string) *ZSliceCmd
  • func (c Client) ZIncrBy(ctx context.Context, key string, increment float64, member string) *FloatCmd
  • func (c Client) ZInter(ctx context.Context, store *ZStore) *StringSliceCmd
  • func (c Client) ZInterCard(ctx context.Context, limit int64, keys …string) *IntCmd
  • func (c Client) ZInterStore(ctx context.Context, destination string, store *ZStore) *IntCmd
  • func (c Client) ZInterWithScores(ctx context.Context, store *ZStore) *ZSliceCmd
  • func (c Client) ZLexCount(ctx context.Context, key, min, max string) *IntCmd
  • func (c Client) ZMPop(ctx context.Context, order string, count int64, keys …string) *ZSliceWithKeyCmd
  • func (c Client) ZMScore(ctx context.Context, key string, members …string) *FloatSliceCmd
  • func (c Client) ZPopMax(ctx context.Context, key string, count …int64) *ZSliceCmd
  • func (c Client) ZPopMin(ctx context.Context, key string, count …int64) *ZSliceCmd
  • func (c Client) ZRandMember(ctx context.Context, key string, count int) *StringSliceCmd
  • func (c Client) ZRandMemberWithScores(ctx context.Context, key string, count int) *ZSliceCmd
  • func (c Client) ZRange(ctx context.Context, key string, start, stop int64) *StringSliceCmd
  • func (c Client) ZRangeArgs(ctx context.Context, z ZRangeArgs) *StringSliceCmd
  • func (c Client) ZRangeArgsWithScores(ctx context.Context, z ZRangeArgs) *ZSliceCmd
  • func (c Client) ZRangeByLex(ctx context.Context, key string, opt *ZRangeBy) *StringSliceCmd
  • func (c Client) ZRangeByScore(ctx context.Context, key string, opt *ZRangeBy) *StringSliceCmd
  • func (c Client) ZRangeByScoreWithScores(ctx context.Context, key string, opt *ZRangeBy) *ZSliceCmd
  • func (c Client) ZRangeStore(ctx context.Context, dst string, z ZRangeArgs) *IntCmd
  • func (c Client) ZRangeWithScores(ctx context.Context, key string, start, stop int64) *ZSliceCmd
  • func (c Client) ZRank(ctx context.Context, key, member string) *IntCmd
  • func (c Client) ZRankWithScore(ctx context.Context, key, member string) *RankWithScoreCmd
  • func (c Client) ZRem(ctx context.Context, key string, members …interface{}) *IntCmd
  • func (c Client) ZRemRangeByLex(ctx context.Context, key, min, max string) *IntCmd
  • func (c Client) ZRemRangeByRank(ctx context.Context, key string, start, stop int64) *IntCmd
  • func (c Client) ZRemRangeByScore(ctx context.Context, key, min, max string) *IntCmd
  • func (c Client) ZRevRange(ctx context.Context, key string, start, stop int64) *StringSliceCmd
  • func (c Client) ZRevRangeByLex(ctx context.Context, key string, opt *ZRangeBy) *StringSliceCmd
  • func (c Client) ZRevRangeByScore(ctx context.Context, key string, opt *ZRangeBy) *StringSliceCmd
  • func (c Client) ZRevRangeByScoreWithScores(ctx context.Context, key string, opt *ZRangeBy) *ZSliceCmd
  • func (c Client) ZRevRangeWithScores(ctx context.Context, key string, start, stop int64) *ZSliceCmd
  • func (c Client) ZRevRank(ctx context.Context, key, member string) *IntCmd
  • func (c Client) ZRevRankWithScore(ctx context.Context, key, member string) *RankWithScoreCmd
  • func (c Client) ZScan(ctx context.Context, key string, cursor uint64, match string, count int64) *ScanCmd
  • func (c Client) ZScore(ctx context.Context, key, member string) *FloatCmd
  • func (c Client) ZUnion(ctx context.Context, store ZStore) *StringSliceCmd
  • func (c Client) ZUnionStore(ctx context.Context, dest string, store *ZStore) *IntCmd
  • func (c Client) ZUnionWithScores(ctx context.Context, store ZStore) *ZSliceCmd

到了这里,关于Go访问Redis代码封装的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处: 如若内容造成侵权/违法违规/事实不符,请点击违法举报进行投诉反馈,一经查实,立即删除!

领支付宝红包 赞助服务器费用

相关文章

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

博客赞助

微信扫一扫打赏

请作者喝杯咖啡吧~博客赞助

支付宝扫一扫领取红包,优惠每天领

二维码1

领取红包

二维码2

领红包