key.go 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. package cache
  2. import (
  3. "time"
  4. )
  5. func (p *RedisCache) Expire(key string, seconds int64) (bool, error) {
  6. if p.isCluster {
  7. return p.cluster.Expire(key, time.Duration(seconds)*time.Second).Result()
  8. }
  9. return p.client.Expire(key, time.Duration(seconds)*time.Second).Result()
  10. }
  11. func (p *RedisCache) Exists(keys ...string) (int64, error) {
  12. if p.isCluster {
  13. n := int64(0)
  14. for _, key := range keys {
  15. v, err := p.cluster.Exists(key).Result()
  16. if err != nil {
  17. return n, err
  18. }
  19. n += v
  20. }
  21. return n, nil
  22. }
  23. return p.client.Exists(keys...).Result()
  24. }
  25. func (p *RedisCache) Del(keys ...string) (int64, error) {
  26. if p.isCluster {
  27. n := int64(0)
  28. for _, key := range keys {
  29. v, err := p.cluster.Del(key).Result()
  30. if err != nil {
  31. return n, err
  32. }
  33. n += v
  34. }
  35. return n, nil
  36. }
  37. return p.client.Del(keys...).Result()
  38. }
  39. func (p *RedisCache) IncrBy(key string, value int64) (int64, error) {
  40. if p.isCluster {
  41. return p.cluster.IncrBy(key, value).Result()
  42. }
  43. return p.client.IncrBy(key, value).Result()
  44. }
  45. func (p *RedisCache) Rename(key string, newkey string) (string, error) {
  46. if p.isCluster {
  47. return p.cluster.Rename(key, newkey).Result()
  48. }
  49. return p.client.Rename(key, newkey).Result()
  50. }