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

Ordered collection operation method

Method list

Method name Parameter Description Notes
zAdd $key, $score1, $member1, …$data Add one or more members to an ordered collection, or update the scores of existing members
zCard $key Get the number of members of an ordered collection
zCount $key, $min, $max Calculate the number of members specifying the interval score in an ordered collection
zInCrBy $key, $increment, $member The fraction of the specified member in the ordered collection plus the increment increment
zInTerStore $destination, array $keys, array $weights = [], $aggregate = ‘SUM’ Computes the intersection of a given set of one or more ordered sets and stores the result set in a new ordered set key
zLexCount $key, $min, $max Calculate the number of members in a specified dictionary interval in an ordered collection
zRange $key, $start, $stop, $withScores = false Returns the members of the specified range in the ordered collection through the index interval
zRangeByLex $key, $min, $max, …$data Returning members of an ordered collection through a dictionary interval
zRangeByScore $key, $min, $max, array $options Returning the members of the specified range by the ordered set by the score
zRank $key, $member Returns the index of the specified member in the ordered collection
zRem $key, $member, …$members Remove one or more members from an ordered collection
zRemRangeByLex $key, $min, $max Remove all members of a given dictionary interval in an ordered collection
zRemRangeByRank $key, $start, $stop Remove all members of a given ranking interval from an ordered collection
zRemRangeByScore $key, $min, $max Remove all members of a given score interval in an ordered collection
zRevRange $key, $start, $stop, $withScores = false Returns the members in the specified interval in the ordered set, through the index, the score is from high to low
zRevRangeByScore $key, $max, $min, array $options Returns the members in the specified fractional interval in the ordered set, sorting the scores from high to low
zRevRank $key, $member Returns the rank of the specified member in the ordered collection, the ordered members are sorted by the fractional value (large to small)
zScore $key, $member Returns the ordered set, the member’s score
zUnionStore $destination, array $keys, array $weights = [], $aggregate = ‘SUM’ Computes the union of a given set of one or more ordered sets and stores them in a new key
zScan $key,&$cursor, $pattern=null, $count=null Iterate over the elements in an ordered collection (including element members and element scores)

::: warning In cluster mode, methods such as zInTerStore, zUnionStore cannot be used. :::

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 = [
  9. 'sortMuster1',
  10. 'sortMuster2',
  11. 'sortMuster3',
  12. 'sortMuster4',
  13. 'sortMuster5',
  14. ];
  15. $member = [
  16. 'member1',
  17. 'member2',
  18. 'member3',
  19. 'member4',
  20. 'member5',
  21. ];
  22. $score = [
  23. 1,
  24. 2,
  25. 3,
  26. 4,
  27. ];
  28. $redis->del($key[0]);
  29. $data = $redis->zAdd($key[0], $score[0], $member[0], $score[1], $member[1]);
  30. var_dump($data);
  31. $data = $redis->zCard($key[0]);
  32. var_dump($data);
  33. $data = $redis->zCount($key[0], 0, 3);
  34. var_dump($data);
  35. $data = $redis->zInCrBy($key[0], 1, $member[1]);
  36. var_dump($data);
  37. $redis->del($key[0]);
  38. $redis->del($key[1]);
  39. $redis->zAdd($key[0], $score[0], $member[0], $score[1], $member[1]);
  40. $redis->zAdd($key[1], $score[0], $member[0], $score[3], $member[3]);
  41. $data = $redis->zInTerStore($key[2], [$key[0], $key[1]], [1, 2]);
  42. var_dump($data);
  43. $data = $redis->zLexCount($key[0], '-', '+');
  44. var_dump($data);
  45. $redis->del($key[0]);
  46. $redis->zAdd($key[0], $score[0], $member[0], $score[1], $member[1], $score[2], $member[2]);
  47. $data = $redis->zRange($key[0], 0, -1, true);
  48. var_dump($data);
  49. $data = $redis->zRangeByLex($key[0], '-', '+');
  50. var_dump($data);
  51. $data = $redis->zRangeByScore($key[0], 2, 3, ['withScores' => true, 'limit' => array(0, 2)]);
  52. var_dump($data);
  53. $data = $redis->zRank($key[0], $member[1]);
  54. var_dump($data);
  55. $data = $redis->zRem($key[0], $member[1], $member[2]);
  56. var_dump($data);
  57. $redis->del($key[0]);
  58. $redis->zAdd($key[0], $score[0], $member[0], $score[1], $member[1], $score[2], $member[2]);
  59. $data = $redis->zRemRangeByLex($key[0], '-', '+');
  60. var_dump($data);
  61. $redis->del($key[0]);
  62. $redis->zAdd($key[0], $score[0], $member[0], $score[1], $member[1], $score[2], $member[2]);
  63. $data = $redis->zRemRangeByRank($key[0], 0, 2);
  64. var_dump($data);
  65. $redis->del($key[0]);
  66. $redis->zAdd($key[0], $score[0], $member[0], $score[1], $member[1], $score[2], $member[2]);
  67. $data = $redis->zRemRangeByScore($key[0], 0, 3);
  68. var_dump($data);
  69. $redis->del($key[0]);
  70. $redis->zAdd($key[0], $score[0], $member[0], $score[1], $member[1], $score[2], $member[2]);
  71. $data = $redis->zRevRange($key[0], 0, 3, true);
  72. var_dump($data);
  73. $redis->del($key[0]);
  74. $redis->zAdd($key[0], $score[0], $member[0], $score[1], $member[1], $score[2], $member[2]);
  75. $data = $redis->zRevRangeByScore($key[0], 3, 0, ['withScores' => true, 'limit' => array(0, 3)]);
  76. var_dump($data);
  77. $data = $redis->zRevRank($key[0], $member[0]);
  78. var_dump($data);
  79. $data = $redis->zScore($key[0], $member[0]);
  80. var_dump($data);
  81. $redis->del($key[0]);
  82. $redis->del($key[1]);
  83. $redis->del($key[2]);
  84. $redis->zAdd($key[0], $score[0], $member[0], $score[1], $member[1]);
  85. $redis->zAdd($key[1], $score[0], $member[0], $score[3], $member[3]);
  86. $data = $redis->zUnionStore($key[2], [$key[1], $key[0]]);
  87. var_dump($data);
  88. $cursor = 0;
  89. $redis->del('a');
  90. $redis->zAdd('a',1,'a1',2,'a2',3,'a3',4,'a4',5,'a5');
  91. $data = [];
  92. do {
  93. $keys = $redis->zScan('a',$cursor,'*',1);
  94. $data = array_merge($data,$keys);
  95. } while ($cursor);
  96. var_dump($data);
  97. })