redis.go 1.1 KB

123456789101112131415161718192021222324252627282930313233343536
  1. package utils
  2. import (
  3. "context"
  4. "eta/eta_mini_crm_ht/utils/redis"
  5. "time"
  6. )
  7. type RedisClient interface {
  8. Get(key string) interface{}
  9. RedisBytes(key string) (data []byte, err error)
  10. RedisString(key string) (data string, err error)
  11. RedisInt(key string) (data int, err error)
  12. Put(key string, val interface{}, timeout time.Duration) error
  13. SetNX(key string, val interface{}, timeout time.Duration) bool
  14. SetEX(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. RunLUA(command string, ctx context.Context, keys []string, args ...interface{}) bool
  23. }
  24. func initRedis(redisType string, conf string) (redisClient RedisClient, err error) {
  25. switch redisType {
  26. case "cluster": // 集群
  27. redisClient, err = redis.InitClusterRedis(conf)
  28. default: // 默认走单机
  29. redisClient, err = redis.InitStandaloneRedis(conf)
  30. }
  31. return
  32. }