redis.go 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. package utils
  2. import (
  3. "eta/eta_task/utils/redis"
  4. "time"
  5. )
  6. type RedisClient interface {
  7. Get(key string) interface{}
  8. GetStr(key string) string
  9. GetInt64(key string) (int64, error)
  10. GetUInt64(key string) (uint64, error)
  11. RedisBytes(key string) (data []byte, err error)
  12. RedisString(key string) (data string, err error)
  13. RedisInt(key string) (data int, err error)
  14. Put(key string, val interface{}, timeout time.Duration) error
  15. SetNX(key string, val interface{}, timeout time.Duration) bool
  16. Delete(key string) error
  17. IsExist(key string) bool
  18. LPush(key string, val interface{}) error
  19. Brpop(key string, callback func([]byte))
  20. LLen(key string) (int64, error)
  21. GetRedisTTL(key string) time.Duration
  22. Incrby(key string, num int) (interface{}, error)
  23. Do(commandName string, args ...interface{}) (reply interface{}, err error)
  24. }
  25. func initRedis(redisType string, conf string) (redisClient RedisClient, err error) {
  26. switch redisType {
  27. case "cluster": // 集群
  28. redisClient, err = redis.InitClusterRedis(conf)
  29. default: // 默认走单机
  30. redisClient, err = redis.InitStandaloneRedis(conf)
  31. }
  32. return
  33. }
  34. // RedisNoKeyErr redis没有key的错误
  35. const RedisNoKeyErr = "redis: nil"