redis_client.go 1.1 KB

123456789101112131415161718192021222324252627
  1. package redis
  2. import (
  3. "context"
  4. "time"
  5. )
  6. // redis接口
  7. type RedisClient interface {
  8. GetString(key string) string
  9. GetStringWithContext(ctx context.Context, key string) string
  10. SetString(key string, val string, expired int) error
  11. SetStringWithContext(ctx context.Context, key string, val string, expired int) error
  12. GetHSet(key string) map[string]string
  13. GetHSetWithContext(ctx context.Context, key string) map[string]string
  14. SetHSet(key string, timeout time.Duration, val ...interface{}) error
  15. SetHSetWithContext(ctx context.Context, key string, timeout time.Duration, val ...interface{}) error
  16. Delete(key string) error
  17. DeleteWithContext(ctx context.Context, key string) error
  18. IsExist(key string) bool
  19. IsExistWithContext(ctx context.Context, key string) bool
  20. Do(commandName string, args ...interface{}) (reply interface{}, err error)
  21. DoWithContext(ctx context.Context, commandName string, args ...interface{}) (reply interface{}, err error)
  22. SetIfNotExist(key string, val string, expired int) bool // 0:设置失败,1:设置成功
  23. SetIfNotExistWithContext(ctx context.Context, key string, val string, expired int) error
  24. }