HashTrait.php 911 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. <?php
  2. namespace tw\redis;
  3. use crmeb\utils\Redis;
  4. trait HashTrait
  5. {
  6. public function get($word, $attr) : string
  7. {
  8. return Redis::hGet($this->key($word), $attr);
  9. }
  10. public function gets($word, $attrs) : array
  11. {
  12. return Redis::hMGet($this->key($word), $attrs);
  13. }
  14. public function set($word, $attr, $value) : bool
  15. {
  16. return Redis::hSet($this->key($word), $attr, $value);
  17. }
  18. public function sets($word, $attrs) : bool
  19. {
  20. return Redis::hMSet($this->key($word), $attrs);
  21. }
  22. public function dels($word, $attrs) : int
  23. {
  24. if (is_string($attrs)) {
  25. return Redis::hDel($this->key($word), $attrs);
  26. }else if (is_array($attrs)) {
  27. return Redis::hDel($this->key($word), ...$attrs);
  28. }
  29. }
  30. public function getAll($word) : array
  31. {
  32. return Redis::hGetAll($this->key($word));
  33. }
  34. }