go-redis-client  - Redis 的 Go 客户端开发包
小码哥 2019-08-17 14:44:31

go-redis-client 是国内团队灵雀云开发的 Go 语言的 Redis 客户端开发包,支持 Redis 单机和集群。

特性

  • 自动键前缀
  • 创建客户端实例时使用独立的参数对象
  • 内部使用 github.com/go-redis/redis 客户端,当前使用的是 gopkg.in/redis.v5
  • 客户端接口

示例

package main

import "redis" github.com/alauda/go-redis-client

func main() {
  // check options.go for more details
  opts := redis.RedisClientOptions{
    Type: 	  redis.ClientNormal,
    Hosts:    []string{"localhost:6379"},
    Password: "123456",
    Database: 0,
  }
  client := redis.NewRedisClient(opts)
  if err := client.Ping().Err(); err != nil {
    panic(err)
  }
  
  // Using cluster mode
  clusterOpts := redis.RedisClientOptions{
    Type:      redis.ClientCluster,
    Hosts:     []string{"localhost:7000","localhost:7001","localhost:7002"},
    Password:  "123456",
    Database:  0,
    // all keys with a prefix
    KeyPrefix: "my-app:",
  }
  clusterClient := redis.NewRedisClient(clusterOpts)
  if err := clusterClient.Ping().Err(); err != nil {
    panic(err)
  }
}

Supported commands

  • Ping
  • Incr
  • IncrBy
  • Decr
  • DecrBy
  • Expire
  • ExpireAt
  • Persist
  • PExpire
  • PExpireAt
  • PTTL
  • TTL
  • Exists
  • Get
  • GetBit
  • GetRange
  • GetSet
  • MGet
  • Dump
  • HExists
  • HGet
  • HGetAll
  • HIncrBy
  • HIncrByFloat
  • HKeys
  • HLen
  • HMGet
  • HMSet
  • HSet
  • HSetNX
  • HVals
  • LIndex
  • LInsert
  • LInsertAfter
  • LInsertBefore
  • LLen
  • LPop
  • LPush
  • LPushX
  • LRange
  • lRem
  • LSet
  • LTrim
  • RPop
  • RPopLPush
  • RPush
  • RPushX
  • Set
  • Append
  • Del
  • Unlink
  • SAdd
  • SCard
  • SDiff
  • SDiffStore
  • SInter
  • SInterStore
  • SIsMember
  • SMembers
  • SMove
  • SPop
  • SPopN
  • SRandMember
  • SRem
  • SUnion
  • SUnionStore
  • ZAdd
  • ZAddNX
  • ZAddXX
  • ZAddCh
  • ZaddNXCh
  • ZIncr
  • ZIncrNX
  • ZIncrXX
  • ZCard
  • ZCount
  • ZIncrBy
  • ZInterStore
  • ZRange
  • ZRangeWithScores
  • ZRangeByScore
  • ZRangeByLex
  • ZRangeByScoreWithScores
  • ZRank
  • ZRem
  • ZREmRangeByRank
  • ZRemRangeByScore
  • ZRemRangeByLex
  • ZRevRange
  • ZRevRangeWithScores
  • ZRevRangeByScore
  • ZRevRangeByLex
  • ZRevRangeByScoreWithScores
  • ZRevRank
  • ZScore
  • ZUnionStore
  • BLPop
  • BRPop
  • BRPopLPush
  • Type
  • Scan
  • SScan
  • ZScan
  • HScan
  • Publish
  • Subscribe

TODO

  •  Update to redis.v6
  •  Support RedisCluster Subscribe
  •  Better support for godoc
  •  Add docker-compose and example application
  •  Add tests