-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathlist_example.php
62 lines (52 loc) · 1.79 KB
/
list_example.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
<?php
require_once __DIR__ . '/../vendor/autoload.php';
use Dazzle\Loop\Model\SelectLoop;
use Dazzle\Loop\Loop;
use Dazzle\Redis\Redis;
$loop = new Loop(new SelectLoop());
//create a new redis client
$endpoint = @$argv[1]?:'tcp://127.0.0.1:6379';
$redis = new Redis($endpoint, $loop);
/**
* Redis List Commands
* @see https://redis.io/commands#list
*/
$redis->on('start', function (Redis $redis) {
//this one is not a command of redis list commands part
$redis->flushDb();
$redis->lPush('t_list', 1, 2, 3, 4, 5)->then(function ($value) {
printf("Push %d elements to a new list\n", $value);
});
$redis->lPop('t_list')->then(function ($value) {
printf("Pop \"%s\" elements from list\n", $value);
});
$redis->lIndex('t_list', 0)->then(function ($value) {
printf("Index 0 element: \"%s\" elements from list\n", $value);
});
$redis->lInsert('t_list', 'after', 4, 10)->then(function ($_) {
printf("New element: \"%s\" insert to list\n", '10');
});
$redis->lLen('t_list')->then(function ($value) {
printf("Now list length: %d\n", $value);
});
$redis->lRange('t_list')->then(function ($value) {
printf("All elements: %s\n", implode(',', $value));
});
$redis->lRem('t_list', 0, 4)->then(function ($value) {
printf("Remove %d element(s) of that value equals 4\n", $value);
});
$redis->lSet('t_list', 0, 3)->then(function ($_) {
printf("Set index 0 elements value to 3.");
});
$redis->lRange('t_list')->then(function ($value) {
printf("In the end,the results should be: %s", implode(',', $value));
});
$redis->end();
});
$redis->on('stop', function () use ($loop) {
$loop->stop();
});
$loop->onStart(function () use ($redis) {
$redis->start();
});
$loop->start();