redis.go 1.2 KB

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