redis.go 975 B

123456789101112131415161718192021222324252627282930313233
  1. package utils
  2. import (
  3. "eta_gn/eta_api/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. Delete(key string) error
  14. IsExist(key string) bool
  15. LPush(key string, val interface{}) error
  16. Brpop(key string, callback func([]byte))
  17. GetRedisTTL(key string) time.Duration
  18. Incrby(key string, num int) (interface{}, error)
  19. Do(commandName string, args ...interface{}) (reply interface{}, err error)
  20. }
  21. func initRedis(redisType string, conf string) (redisClient RedisClient, err error) {
  22. switch redisType {
  23. case "cluster": // 集群
  24. redisClient, err = redis.InitClusterRedis(conf)
  25. default: // 默认走单机
  26. redisClient, err = redis.InitStandaloneRedis(conf)
  27. }
  28. return
  29. }