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

Collection operation method

Method list

Method name Parameter Description Notes
sAdd $key, …$data Add one or more members to the collection
sCard $key Get the number of members of the collection
sDiff $key1, …$keys Returns the difference set for all sets
sMembers $destination, …$keys Return all members in the collection
sDiffStore $key1, …$keys Returns the difference set for all collections and stores them in destination
sInter $destination, …$keys Returns the intersection of all the given sets
sInterStore $key, $member Returns the intersection of all the collections given and stored in destination
sIsMember $key Determine if the member element is a member of the collection key
sMove $source, $destination, $member Move the member element from the source collection to the destination collection
sPop $key Remove and return a random element in the collection
sRandMemBer $key, $count = null Return one or more random numbers in the collection
sRem $key, $member1, …$members Remove one or more members from the collection
sUnion $key1, …$keys Returns the union of all given collections
sUnIonStore $destination, $key1, …$keys The union of all given collections is stored in the destination collection
sScan $key,&$cursor, $pattern=null, $count=null Iterating over the elements in the collection

::: warning In cluster mode, sDiff, sDiffStore, sInter, sMove, sUnion, sUnIonStore, etc. 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. 'muster1',
  10. 'muster2',
  11. 'muster3',
  12. 'muster4',
  13. 'muster5',
  14. ];
  15. $value = [
  16. '1',
  17. '2',
  18. '3',
  19. '4',
  20. ];
  21. $redis->del($key[0]);
  22. $redis->del($key[1]);
  23. $data = $redis->sAdd($key[0], $value[0], $value[1]);
  24. var_dump($data);
  25. $data = $redis->sCard($key[0]);
  26. var_dump($data);
  27. $redis->sAdd($key[1], $value[0], $value[2]);
  28. $data = $redis->sDiff($key[0], $key[1]);
  29. var_dump($data);
  30. $data = $redis->sDiff($key[1], $key[0]);
  31. var_dump($data);
  32. $data = $redis->sMembers($key[0]);
  33. var_dump($data);
  34. $data = $redis->sMembers($key[1]);
  35. var_dump($data);
  36. $data = $redis->sDiffStore($key[2], $key[0], $key[1]);
  37. var_dump($data);
  38. $data = $redis->sInter($key[0], $key[1]);
  39. var_dump($data);
  40. $data = $redis->sInterStore($key[3], $key[0], $key[1]);
  41. var_dump($data);
  42. $data = $redis->sIsMember($key[0], $value[0]);
  43. var_dump($data);
  44. $data = $redis->sMove($key[0], $key[1], $value[1]);
  45. var_dump($data);
  46. $data = $redis->sPop($key[0]);
  47. var_dump($data);
  48. $redis->del($key[3]);
  49. $redis->sAdd($key[3], $value[0], $value[1], $value[2], $value[3]);
  50. $data = $redis->sRandMemBer($key[3], 4);
  51. var_dump($data);
  52. $data = $redis->sRem($key[3], $value[0], $value[1], $value[2], $value[3]);
  53. var_dump($data);
  54. $data = $redis->sUnion($key[0], $key[1]);
  55. var_dump($data);
  56. $redis->del($key[1]);
  57. $redis->del($key[2]);
  58. $redis->del($key[3]);
  59. $redis->del($key[4]);
  60. $redis->sAdd($key[1], 1, 2, 3, 4);
  61. $redis->sAdd($key[2], 5);
  62. $redis->sAdd($key[3], 6, 7);
  63. $data = $redis->sUnIonStore($key[4], $key[1], $key[2], $key[3]);
  64. var_dump($data);
  65. $cursor = 0;
  66. $redis->del('a');
  67. $redis->sAdd('a','a1','a2','a3','a4','a5');
  68. $data= [];
  69. do {
  70. $keys = $redis->sScan('a',$cursor,'*',1);
  71. $data = array_merge($data,$keys);
  72. } while ($cursor);
  73. var_dump($data);
  74. });