title: Redis coroutine client meta:

  • name: description content: Redis coroutine client,Implemented by swoole coroutine client,Covers the method of redis 99%
  • name: keywords content: swoole|swoole extension|swoole framework|EasySwoole redis| Swoole Redis coroutine client|swoole Redis|Redis coroutine

Hash operation method

Method list

Method name Parameter Description Notes
hDel $key, …$field Delete key, multiple
hExists $key, $field Whether the query field exists
hGet $key, $field Get a field value
hGetAll $key Get all the field values of this key
hSet $key, $field, $value Set the field value of the key
hValS $key Get all the values in the hash table
hKeys $key Get the fields in all hash tables
hLen $key Get the number of fields in the hash table
hMGet $key, $hashKeys Get the value of all the given field $hashKeys array
hMSet $key, $data Set multiple $data key-value pairs to $key at the same time
hIncrBy $key, $field, $increment Add $increment to the specified field
hIncrByFloat $key, $field, $increment Add a floating point number to the specified field $increment
hSetNx $key, $field, $value Set the value of $field only if $filed does not exist
hScan $key,&$cursor, $pattern=null, $count=null Iterate over the key-value pairs in the hash table.

Instance

  1. go(function () {
  2. $redis = new \EasySwoole\Redis\Redis(new \EasySwoole\Redis\Config\RedisConfig([
  3. 'host' => '127.0.0.1',
  4. 'port' => '6379',
  5. 'auth' => 'easyswoole',
  6. 'serialize' => \EasySwoole\Redis\Config\RedisConfig::SERIALIZE_NONE
  7. ]));
  8. $key = 'hKey';
  9. $field = [
  10. 'hField1',
  11. 'hField2',
  12. 'hField3',
  13. 'hField4',
  14. 'hField5',
  15. ];
  16. $value = [
  17. 1,
  18. 2,
  19. 3,
  20. 4,
  21. 5,
  22. ];
  23. $redis->del($key);
  24. $data = $redis->hSet($key, $field[0], $value[0]);
  25. var_dump($data);
  26. $data = $redis->hGet($key, $field[0]);
  27. var_dump($data);
  28. $data = $redis->hExists($key, $field[0]);
  29. var_dump($data);
  30. $data = $redis->hDel($key, $field[0]);
  31. var_dump($data);
  32. $data = $redis->hExists($key, $field[0]);
  33. var_dump($data);
  34. $data = $redis->hMSet($key, [
  35. "{$field[0]}" => $value[0],
  36. "{$field[1]}" => $value[1],
  37. "{$field[2]}" => $value[2],
  38. "{$field[3]}" => $value[3],
  39. "{$field[4]}" => $value[4],
  40. ]);
  41. var_dump($data);
  42. $data = $redis->hValS($key);
  43. var_dump($data);
  44. $data = $redis->hGetAll($key);
  45. var_dump($data);
  46. $data = $redis->hKeys($key);
  47. var_dump($data);
  48. $data = $redis->hLen($key);
  49. var_dump($data);
  50. $data = $redis->hMGet($key, [$field[0], $field[1], $field[2]]);
  51. var_dump($data);
  52. $data = $redis->hIncrBy($key, $field[4], 1);
  53. var_dump($data);
  54. $data = $redis->hIncrByFloat($key, $field[1], 1.1);
  55. var_dump($data);
  56. $data = $redis->hSetNx($key, $field[0], 1);
  57. var_dump($data);
  58. $data = $redis->hSetNx($key, $field[0] . 'a', 1);
  59. var_dump($data);
  60. var_dump($redis->hGet($key, $field[0] . 'a'));
  61. $cursor = 0;
  62. $redis->del('a');
  63. $redis->hMSet('a',[
  64. 'a'=>'tioncico',
  65. 'b'=>'tioncico',
  66. 'c'=>'tioncico',
  67. 'd'=>'tioncico',
  68. 'e'=>'tioncico',
  69. 'f'=>'tioncico',
  70. 'g'=>'tioncico',
  71. 'h'=>'tioncico',
  72. ]);
  73. $data = [];
  74. do {
  75. $keys = $redis->hScan('a',$cursor);
  76. $data = array_merge($data,$keys);
  77. var_dump($keys);
  78. } while ($cursor);
  79. });