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

List operation method

Method list

Method name Parameter Description Notes
lPush $key, …$data Insert one or more values ​​into the list header
bLPop $keys,$timeout Move out and get the first element of the $keys list. If there are no elements in the $keys list, it will block the list until it waits for a timeout or finds that the element can be popped up. $keys can be either string or an array
bRPop $keys,$timeout Move out and get the last element of the $keys list. If there are no elements in the $keys list, it will block the list until it waits for a timeout or finds that the element can be popped up. $keys can be either string or an array
bRPopLPush $source, $destination, $timeout Pops a value from the list, inserts the pop-up element into another list and returns it; if the list has no elements, it blocks the list until it waits for a timeout or finds a pop-up element.
rPopLPush $source, $destination Remove the last element of the list and add the element to another list and return
lIndex $key,$index Get the elements in the list by index
lLen $key Get list length
lInsert $key,$bool,$pivot,$value Insert elements before or after the elements of the list
rPush $key, …$data Add one or more values ​​to the list
lRange $key,$start,$stop Get the elements in the specified range of the list
lPop $key Move out and get the first element of the list
rPop $key Move out and get the last element of the list
lPuShx $key,$value Insert a value into the existing list header
rPuShx $key,$value Add a value to an existing list
lRem $key,$count,$value Remove list element
lSet $key,$index,$value Set the value of a list element by index
lTrim $key,$start,$stop Trim a list, that is, let the list retain only the elements in the specified range, and elements that are not within the specified range will be deleted.

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. 'listKey1',
  10. 'listKey2',
  11. 'listKey3',
  12. ];
  13. $value = [
  14. 'a', 'b', 'c', 'd'
  15. ];
  16. $redis->flushAll();
  17. //When testing null
  18. $data = $redis->bLPop([$key[0],$key[1]], 1);
  19. var_dump($data);
  20. $data = $redis->lPush($key[0], $value[0], $value[1]);
  21. var_dump($data);
  22. //When testing null
  23. $data = $redis->bLPop([$key[1]], 1);
  24. var_dump($data);
  25. $data = $redis->bRPop([$key[1]], 1);
  26. var_dump($data);
  27. $data = $redis->bLPop([$key[0],$key[1]], 1);
  28. var_dump($data);
  29. $data = $redis->bRPop([$key[0],$key[1]], 1);
  30. var_dump($data);
  31. $redis->del($key[0]);
  32. $redis->lPush($key[0], $value[0], $value[1]);
  33. $data = $redis->bRPopLPush($key[0], $key[1], 1);
  34. var_dump($data);
  35. $redis->del($key[0]);
  36. $redis->lPush($key[0], $value[0], $value[1]);
  37. $data = $redis->rPopLPush($key[0], $key[1]);
  38. var_dump($data);
  39. $redis->del($key[0]);
  40. $redis->lPush($key[0], $value[0], $value[1]);
  41. $data = $redis->lIndex($key[0], 1);
  42. var_dump($data);
  43. $data = $redis->lLen($key[0]);
  44. var_dump($data);
  45. $data = $redis->lInsert($key[0], true, 'b', 'c');
  46. var_dump($data);
  47. $data = $redis->lInsert($key[0], true, 'd', 'c');
  48. var_dump($data);
  49. $redis->del($key[1]);
  50. $data = $redis->rPush($key[1], $value[0], $value[2], $value[1]);
  51. var_dump($data);
  52. $data = $redis->lRange($key[1], 0, 3);
  53. var_dump($data);
  54. $data = $redis->lPop($key[1]);
  55. var_dump($data);
  56. $data = $redis->rPop($key[1]);
  57. var_dump($data);
  58. $data = $redis->lPuShx($key[1], 'x');
  59. var_dump($data);
  60. $data = $redis->rPuShx($key[1], 'z');
  61. var_dump($data);
  62. $redis->del($key[1]);
  63. $redis->rPush($key[1], $value[0], $value[0], $value[0]);
  64. $data = $redis->lRem($key[1], 1, $value[0]);
  65. var_dump($data);
  66. $data = $redis->lSet($key[1], 0, 'xx');
  67. var_dump($data);
  68. $data = $redis->lTrim($key[1], 0, 2);
  69. var_dump($data);
  70. });