redis.go 1.0 KB

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