-
Notifications
You must be signed in to change notification settings - Fork 799
/
RedisCluster.php
3573 lines (3401 loc) · 121 KB
/
RedisCluster.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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<?php
/**
* Helper autocomplete for php redis cluster extension.
* Based on the phpredis-phpdoc by Max Kamashev (https://github.com/ukko/phpredis-phpdoc)
*
* @author Tommy Zheng <tommy@vlv.pw>
* @link https://github.com/zgb7mtr/phpredis_cluster_phpdoc
*
* @method mixed eval($script, $args = array(), $numKeys = 0)
*/
class RedisCluster
{
public const AFTER = 'after';
public const BEFORE = 'before';
/**
* Options
*/
public const OPT_SERIALIZER = 1;
public const OPT_PREFIX = 2;
public const OPT_READ_TIMEOUT = 3;
public const OPT_SCAN = 4;
public const OPT_SLAVE_FAILOVER = 5;
/**
* Cluster options
*/
public const FAILOVER_NONE = 0;
public const FAILOVER_ERROR = 1;
public const FAILOVER_DISTRIBUTE = 2;
public const FAILOVER_DISTRIBUTE_SLAVES = 3;
/**
* SCAN options
*/
public const SCAN_NORETRY = 0;
public const SCAN_RETRY = 1;
/**
* @since 5.3.0
*/
public const SCAN_PREFIX = 2;
/**
* @since 5.3.0
*/
public const SCAN_NOPREFIX = 3;
/**
* Serializers
*/
public const SERIALIZER_NONE = 0;
public const SERIALIZER_PHP = 1;
public const SERIALIZER_IGBINARY = 2;
public const SERIALIZER_MSGPACK = 3;
public const SERIALIZER_JSON = 4;
/**
* Multi
*/
public const ATOMIC = 0;
public const MULTI = 1;
public const PIPELINE = 2;
/**
* Type
*/
public const REDIS_NOT_FOUND = 0;
public const REDIS_STRING = 1;
public const REDIS_SET = 2;
public const REDIS_LIST = 3;
public const REDIS_ZSET = 4;
public const REDIS_HASH = 5;
/**
* Creates a Redis Cluster client
*
* @param string|null $name
* @param array|null $seeds
* @param int|float $timeout
* @param int|float $readTimeout
* @param bool $persistent
* @param mixed $auth
* @param array|null $context
* @throws RedisClusterException
*
* @example
* <pre>
* // Declaring a cluster with an array of seeds
* $redisCluster = new RedisCluster(null,['127.0.0.1:6379']);
*
* // Loading a cluster configuration by name
* // In order to load a named array, one must first define the seed nodes in redis.ini.
* // The following lines would define the cluster 'mycluster', and be loaded automatically by phpredis.
*
* // # In redis.ini
* // redis.clusters.seeds = "mycluster[]=localhost:7000&test[]=localhost:7001"
* // redis.clusters.timeout = "mycluster=5"
* // redis.clusters.read_timeout = "mycluster=10"
* // redis.clusters.auth = "mycluster=password" OR ['user' => 'foo', 'pass' => 'bar] as example
*
* //Then, this cluster can be loaded by doing the following
*
* $redisClusterPro = new RedisCluster('mycluster');
* $redisClusterDev = new RedisCluster('test');
* </pre>
*/
public function __construct($name, $seeds = null, $timeout = null, $readTimeout = null, $persistent = false, $auth = null, $context = null) {}
/**
* Disconnects from the RedisCluster instance, except when pconnect is used.
*/
public function close() {}
/**
* Get the value related to the specified key
*
* @param string $key
*
* @return string|false If key didn't exist, FALSE is returned. Otherwise, the value related to this key is
* returned.
*
* @link https://redis.io/commands/get
* @example
* <pre>
* $redisCluster->get('key');
* </pre>
*/
public function get($key) {}
/**
* Set the string value in argument as value of the key.
*
* @since If you're using Redis >= 2.6.12, you can pass extended options as explained in example
*
* @param string $key
* @param string $value
* @param int|array $timeout If you pass an integer, phpredis will redirect to SETEX, and will try to use Redis
* >= 2.6.12 extended options if you pass an array with valid values.
*
* @return bool TRUE if the command is successful.
*
* @link https://redis.io/commands/set
* @example
* <pre>
* // Simple key -> value set
* $redisCluster->set('key', 'value');
*
* // Will redirect, and actually make an SETEX call
* $redisCluster->set('key','value', 10);
*
* // Will set the key, if it doesn't exist, with a ttl of 10 seconds
* $redisCluster->set('key', 'value', Array('nx', 'ex'=>10));
*
* // Will set a key, if it does exist, with a ttl of 1000 milliseconds
* $redisCluster->set('key', 'value', Array('xx', 'px'=>1000));
* </pre>
*/
public function set($key, $value, $timeout = null) {}
/**
* Returns the values of all specified keys.
*
* For every key that does not hold a string value or does not exist,
* the special value false is returned. Because of this, the operation never fails.
*
* @param array $array
*
* @return array
*
* @link https://redis.io/commands/mget
* @example
* <pre>
* $redisCluster->del('x', 'y', 'z', 'h'); // remove x y z
* $redisCluster->mset(array('x' => 'a', 'y' => 'b', 'z' => 'c'));
* $redisCluster->hset('h', 'field', 'value');
* var_dump($redisCluster->mget(array('x', 'y', 'z', 'h')));
* // Output:
* // array(3) {
* // [0]=>
* // string(1) "a"
* // [1]=>
* // string(1) "b"
* // [2]=>
* // string(1) "c"
* // [3]=>
* // bool(false)
* // }
* </pre>
*/
public function mget(array $array) {}
/**
* Sets multiple key-value pairs in one atomic command.
* MSETNX only returns TRUE if all the keys were set (see SETNX).
*
* @param array $array Pairs: array(key => value, ...)
*
* @return bool TRUE in case of success, FALSE in case of failure.
* @link https://redis.io/commands/mset
* @example
* <pre>
* $redisCluster->mset(array('key0' => 'value0', 'key1' => 'value1'));
* var_dump($redisCluster->get('key0'));
* var_dump($redisCluster->get('key1'));
* // Output:
* // string(6) "value0"
* // string(6) "value1"
* </pre>
*/
public function mset(array $array) {}
/**
* @see mset()
*
* @param array $array
*
* @return int 1 (if the keys were set) or 0 (no key was set)
* @link https://redis.io/commands/msetnx
*/
public function msetnx(array $array) {}
/**
* Remove specified keys.
*
* @param int|string|array $key1 An array of keys, or an undefined number of parameters, each a key: key1 key2 key3
* ... keyN
* @param int|string ...$otherKeys
*
* @return int Number of keys deleted.
* @link https://redis.io/commands/del
* @example
* <pre>
* $redisCluster->set('key1', 'val1');
* $redisCluster->set('key2', 'val2');
* $redisCluster->set('key3', 'val3');
* $redisCluster->set('key4', 'val4');
* $redisCluster->del('key1', 'key2'); // return 2
* $redisCluster->del(array('key3', 'key4')); // return 2
* </pre>
*/
public function del($key1, ...$otherKeys) {}
/**
* Set the string value in argument as value of the key, with a time to live.
*
* @param string $key
* @param int $ttl
* @param mixed $value
*
* @return bool TRUE if the command is successful.
* @link https://redis.io/commands/setex
* @example
* <pre>
* $redisCluster->setex('key', 3600, 'value'); // sets key → value, with 1h TTL.
* </pre>
*/
public function setex($key, $ttl, $value) {}
/**
* PSETEX works exactly like SETEX with the sole difference that the expire time is specified in milliseconds
* instead of seconds.
*
* @param string $key
* @param int $ttl
* @param string $value
*
* @return bool TRUE if the command is successful.
* @link https://redis.io/commands/psetex
* @example
* <pre>
* $redisCluster->psetex('key', 1000, 'value'); // sets key → value, with 1s TTL.
* </pre>
*/
public function psetex($key, $ttl, $value) {}
/**
* Set the string value in argument as value of the key if the key doesn't already exist in the database.
*
* @param string $key
* @param string $value
*
* @return bool TRUE in case of success, FALSE in case of failure.
* @link https://redis.io/commands/setnx
* @example
* <pre>
* $redisCluster->setnx('key', 'value'); // return TRUE
* $redisCluster->setnx('key', 'value'); // return FALSE
* </pre>
*/
public function setnx($key, $value) {}
/**
* Sets a value and returns the previous entry at that key.
*
* @param string $key
* @param string $value
*
* @return string A string, the previous value located at this key.
* @link https://redis.io/commands/getset
* @example
* <pre>
* $redisCluster->set('x', '42');
* $exValue = $redisCluster->getSet('x', 'lol'); // return '42', replaces x by 'lol'
* $newValue = $redisCluster->get('x'); // return 'lol'
* </pre>
*/
public function getSet($key, $value) {}
/**
* Verify if the specified key exists.
*
* @param string $key
*
* @return bool If the key exists, return TRUE, otherwise return FALSE.
* @link https://redis.io/commands/exists
* @example
* <pre>
* $redisCluster->set('key', 'value');
* $redisCluster->exists('key'); // TRUE
* $redisCluster->exists('NonExistingKey'); // FALSE
* </pre>
*/
public function exists($key) {}
/**
* Returns the keys that match a certain pattern.
*
* @param string $pattern pattern, using '*' as a wildcard.
*
* @return array of STRING: The keys that match a certain pattern.
* @link https://redis.io/commands/keys
* @example
* <pre>
* $allKeys = $redisCluster->keys('*'); // all keys will match this.
* $keyWithUserPrefix = $redisCluster->keys('user*');
* </pre>
*/
public function keys($pattern) {}
/**
* Returns the type of data pointed by a given key.
*
* @param string $key
*
* @return int
*
* Depending on the type of the data pointed by the key,
* this method will return the following value:
* - string: RedisCluster::REDIS_STRING
* - set: RedisCluster::REDIS_SET
* - list: RedisCluster::REDIS_LIST
* - zset: RedisCluster::REDIS_ZSET
* - hash: RedisCluster::REDIS_HASH
* - other: RedisCluster::REDIS_NOT_FOUND
* @link https://redis.io/commands/type
* @example $redisCluster->type('key');
*/
public function type($key) {}
/**
* Returns and removes the first element of the list.
*
* @param string $key
*
* @return string|false if command executed successfully BOOL FALSE in case of failure (empty list)
* @link https://redis.io/commands/lpop
* @example
* <pre>
* $redisCluster->rPush('key1', 'A');
* $redisCluster->rPush('key1', 'B');
* $redisCluster->rPush('key1', 'C');
* var_dump( $redisCluster->lRange('key1', 0, -1) );
* // Output:
* // array(3) {
* // [0]=> string(1) "A"
* // [1]=> string(1) "B"
* // [2]=> string(1) "C"
* // }
* $redisCluster->lPop('key1');
* var_dump( $redisCluster->lRange('key1', 0, -1) );
* // Output:
* // array(2) {
* // [0]=> string(1) "B"
* // [1]=> string(1) "C"
* // }
* </pre>
*/
public function lPop($key) {}
/**
* Returns and removes the last element of the list.
*
* @param string $key
*
* @return string|false if command executed successfully BOOL FALSE in case of failure (empty list)
* @link https://redis.io/commands/rpop
* @example
* <pre>
* $redisCluster->rPush('key1', 'A');
* $redisCluster->rPush('key1', 'B');
* $redisCluster->rPush('key1', 'C');
* var_dump( $redisCluster->lRange('key1', 0, -1) );
* // Output:
* // array(3) {
* // [0]=> string(1) "A"
* // [1]=> string(1) "B"
* // [2]=> string(1) "C"
* // }
* $redisCluster->rPop('key1');
* var_dump( $redisCluster->lRange('key1', 0, -1) );
* // Output:
* // array(2) {
* // [0]=> string(1) "A"
* // [1]=> string(1) "B"
* // }
* </pre>
*/
public function rPop($key) {}
/**
* Set the list at index with the new value.
*
* @param string $key
* @param int $index
* @param string $value
*
* @return bool TRUE if the new value is setted. FALSE if the index is out of range, or data type identified by key
* is not a list.
* @link https://redis.io/commands/lset
* @example
* <pre>
* $redisCluster->rPush('key1', 'A');
* $redisCluster->rPush('key1', 'B');
* $redisCluster->rPush('key1', 'C'); // key1 => [ 'A', 'B', 'C' ]
* $redisCluster->lGet('key1', 0); // 'A'
* $redisCluster->lSet('key1', 0, 'X');
* $redisCluster->lGet('key1', 0); // 'X'
* </pre>
*/
public function lSet($key, $index, $value) {}
/**
* Removes and returns a random element from the set value at Key.
*
* @param string $key
*
* @return string "popped" value
* bool FALSE if set identified by key is empty or doesn't exist.
* @link https://redis.io/commands/spop
* @example
* <pre>
* $redisCluster->sAdd('key1' , 'set1');
* $redisCluster->sAdd('key1' , 'set2');
* $redisCluster->sAdd('key1' , 'set3');
* var_dump($redisCluster->sMembers('key1'));// 'key1' => {'set3', 'set1', 'set2'}
* $redisCluster->sPop('key1');// 'set1'
* var_dump($redisCluster->sMembers('key1'));// 'key1' => {'set3', 'set2'}
* $redisCluster->sPop('key1');// 'set3',
* var_dump($redisCluster->sMembers('key1'));// 'key1' => {'set2'}
* </pre>
*/
public function sPop($key) {}
/**
* Adds the string values to the head (left) of the list. Creates the list if the key didn't exist.
* If the key exists and is not a list, FALSE is returned.
*
* @param string $key
* @param string $value1 String, value to push in key
* @param string $value2 Optional
* @param string $valueN Optional
*
* @return int|false The new length of the list in case of success, FALSE in case of Failure.
* @link https://redis.io/commands/lpush
* @example
* <pre>
* $redisCluster->lPush('l', 'v1', 'v2', 'v3', 'v4') // int(4)
* var_dump( $redisCluster->lRange('l', 0, -1) );
* //// Output:
* // array(4) {
* // [0]=> string(2) "v4"
* // [1]=> string(2) "v3"
* // [2]=> string(2) "v2"
* // [3]=> string(2) "v1"
* // }
* </pre>
*/
public function lPush($key, $value1, $value2 = null, $valueN = null) {}
/**
* Adds the string values to the tail (right) of the list. Creates the list if the key didn't exist.
* If the key exists and is not a list, FALSE is returned.
*
* @param string $key
* @param string $value1 String, value to push in key
* @param string $value2 Optional
* @param string $valueN Optional
*
* @return int|false The new length of the list in case of success, FALSE in case of Failure.
* @link https://redis.io/commands/rpush
* @example
* <pre>
* $redisCluster->rPush('r', 'v1', 'v2', 'v3', 'v4'); // int(4)
* var_dump( $redisCluster->lRange('r', 0, -1) );
* //// Output:
* // array(4) {
* // [0]=> string(2) "v1"
* // [1]=> string(2) "v2"
* // [2]=> string(2) "v3"
* // [3]=> string(2) "v4"
* // }
* </pre>
*/
public function rPush($key, $value1, $value2 = null, $valueN = null) {}
/**
* BLPOP is a blocking list pop primitive.
* It is the blocking version of LPOP because it blocks the connection when
* there are no elements to pop from any of the given lists.
* An element is popped from the head of the first list that is non-empty,
* with the given keys being checked in the order that they are given.
*
* @param array $keys Array containing the keys of the lists
* Or STRING Key1 STRING Key2 STRING Key3 ... STRING Keyn
* @param int $timeout Timeout
*
* @return array array('listName', 'element')
* @link https://redis.io/commands/blpop
* @example
* <pre>
* // Non blocking feature
* $redisCluster->lPush('key1', 'A');
* $redisCluster->del('key2');
*
* $redisCluster->blPop('key1', 'key2', 10); // array('key1', 'A')
* // OR
* $redisCluster->blPop(array('key1', 'key2'), 10); // array('key1', 'A')
*
* $redisCluster->brPop('key1', 'key2', 10); // array('key1', 'A')
* // OR
* $redisCluster->brPop(array('key1', 'key2'), 10); // array('key1', 'A')
*
* // Blocking feature
*
* // process 1
* $redisCluster->del('key1');
* $redisCluster->blPop('key1', 10);
* // blocking for 10 seconds
*
* // process 2
* $redisCluster->lPush('key1', 'A');
*
* // process 1
* // array('key1', 'A') is returned
* </pre>
*/
public function blPop(array $keys, $timeout) {}
/**
* BRPOP is a blocking list pop primitive.
* It is the blocking version of RPOP because it blocks the connection when
* there are no elements to pop from any of the given lists.
* An element is popped from the tail of the first list that is non-empty,
* with the given keys being checked in the order that they are given.
* See the BLPOP documentation(https://redis.io/commands/blpop) for the exact semantics,
* since BRPOP is identical to BLPOP with the only difference being that
* it pops elements from the tail of a list instead of popping from the head.
*
* @param array $keys Array containing the keys of the lists
* Or STRING Key1 STRING Key2 STRING Key3 ... STRING Keyn
* @param int $timeout Timeout
*
* @return array array('listName', 'element')
* @link https://redis.io/commands/brpop
* @example
* <pre>
* // Non blocking feature
* $redisCluster->lPush('key1', 'A');
* $redisCluster->del('key2');
*
* $redisCluster->blPop('key1', 'key2', 10); // array('key1', 'A')
* // OR
* $redisCluster->blPop(array('key1', 'key2'), 10); // array('key1', 'A')
*
* $redisCluster->brPop('key1', 'key2', 10); // array('key1', 'A')
* // OR
* $redisCluster->brPop(array('key1', 'key2'), 10); // array('key1', 'A')
*
* // Blocking feature
*
* // process 1
* $redisCluster->del('key1');
* $redisCluster->blPop('key1', 10);
* // blocking for 10 seconds
*
* // process 2
* $redisCluster->lPush('key1', 'A');
*
* // process 1
* // array('key1', 'A') is returned
* </pre>
*/
public function brPop(array $keys, $timeout) {}
/**
* Adds the string value to the tail (right) of the list if the ist exists. FALSE in case of Failure.
*
* @param string $key
* @param string $value String, value to push in key
*
* @return int|false The new length of the list in case of success, FALSE in case of Failure.
* @link https://redis.io/commands/rpushx
* @example
* <pre>
* $redisCluster->del('key1');
* $redisCluster->rPushx('key1', 'A'); // returns 0
* $redisCluster->rPush('key1', 'A'); // returns 1
* $redisCluster->rPushx('key1', 'B'); // returns 2
* $redisCluster->rPushx('key1', 'C'); // returns 3
* // key1 now points to the following list: [ 'A', 'B', 'C' ]
* </pre>
*/
public function rPushx($key, $value) {}
/**
* Adds the string value to the head (left) of the list if the list exists.
*
* @param string $key
* @param string $value String, value to push in key
*
* @return int|false The new length of the list in case of success, FALSE in case of Failure.
* @link https://redis.io/commands/lpushx
* @example
* <pre>
* $redisCluster->del('key1');
* $redisCluster->lPushx('key1', 'A'); // returns 0
* $redisCluster->lPush('key1', 'A'); // returns 1
* $redisCluster->lPushx('key1', 'B'); // returns 2
* $redisCluster->lPushx('key1', 'C'); // returns 3
* // key1 now points to the following list: [ 'C', 'B', 'A' ]
* </pre>
*/
public function lPushx($key, $value) {}
/**
* Insert value in the list before or after the pivot value. the parameter options
* specify the position of the insert (before or after). If the list didn't exists,
* or the pivot didn't exists, the value is not inserted.
*
* @param string $key
* @param string $position RedisCluster::BEFORE | RedisCluster::AFTER
* @param string $pivot
* @param string $value
*
* @return int The number of the elements in the list, -1 if the pivot didn't exists.
* @link https://redis.io/commands/linsert
* @example
* <pre>
* $redisCluster->del('key1');
* $redisCluster->lInsert('key1', RedisCluster::AFTER, 'A', 'X'); // 0
*
* $redisCluster->lPush('key1', 'A');
* $redisCluster->lPush('key1', 'B');
* $redisCluster->lPush('key1', 'C');
*
* $redisCluster->lInsert('key1', RedisCluster::BEFORE, 'C', 'X'); // 4
* $redisCluster->lRange('key1', 0, -1); // array('X', 'C', 'B', 'A')
*
* $redisCluster->lInsert('key1', RedisCluster::AFTER, 'C', 'Y'); // 5
* $redisCluster->lRange('key1', 0, -1); // array('X', 'C', 'Y', 'B', 'A')
*
* $redisCluster->lInsert('key1', RedisCluster::AFTER, 'W', 'value'); // -1
* </pre>
*/
public function lInsert($key, $position, $pivot, $value) {}
/**
* Return the specified element of the list stored at the specified key.
* 0 the first element, 1 the second ... -1 the last element, -2 the penultimate ...
* Return FALSE in case of a bad index or a key that doesn't point to a list.
*
* @param string $key
* @param int $index
*
* @return string|false the element at this index
* Bool FALSE if the key identifies a non-string data type, or no value corresponds to this index in the list Key.
* @link https://redis.io/commands/lindex
* @example
* <pre>
* $redisCluster->rPush('key1', 'A');
* $redisCluster->rPush('key1', 'B');
* $redisCluster->rPush('key1', 'C'); // key1 => [ 'A', 'B', 'C' ]
* $redisCluster->lGet('key1', 0); // 'A'
* $redisCluster->lGet('key1', -1); // 'C'
* $redisCluster->lGet('key1', 10); // `FALSE`
* </pre>
*/
public function lIndex($key, $index) {}
/**
* Removes the first count occurrences of the value element from the list.
* If count is zero, all the matching elements are removed. If count is negative,
* elements are removed from tail to head.
*
* @param string $key
* @param string $value
* @param int $count
*
* @return int the number of elements to remove
* bool FALSE if the value identified by key is not a list.
* @link https://redis.io/commands/lrem
* @example
* <pre>
* $redisCluster->lPush('key1', 'A');
* $redisCluster->lPush('key1', 'B');
* $redisCluster->lPush('key1', 'C');
* $redisCluster->lPush('key1', 'A');
* $redisCluster->lPush('key1', 'A');
*
* $redisCluster->lRange('key1', 0, -1); // array('A', 'A', 'C', 'B', 'A')
* $redisCluster->lRem('key1', 'A', 2); // 2
* $redisCluster->lRange('key1', 0, -1); // array('C', 'B', 'A')
* </pre>
*/
public function lRem($key, $value, $count) {}
/**
* A blocking version of rpoplpush, with an integral timeout in the third parameter.
*
* @param string $srcKey
* @param string $dstKey
* @param int $timeout
*
* @return string|false The element that was moved in case of success, FALSE in case of timeout.
* @link https://redis.io/commands/brpoplpush
*/
public function brpoplpush($srcKey, $dstKey, $timeout) {}
/**
* Pops a value from the tail of a list, and pushes it to the front of another list.
* Also return this value.
*
* @since redis >= 1.2
*
* @param string $srcKey
* @param string $dstKey
*
* @return string|false The element that was moved in case of success, FALSE in case of failure.
* @link https://redis.io/commands/rpoplpush
* @example
* <pre>
* $redisCluster->del('x', 'y');
*
* $redisCluster->lPush('x', 'abc');
* $redisCluster->lPush('x', 'def');
* $redisCluster->lPush('y', '123');
* $redisCluster->lPush('y', '456');
*
* // move the last of x to the front of y.
* var_dump($redisCluster->rpoplpush('x', 'y'));
* var_dump($redisCluster->lRange('x', 0, -1));
* var_dump($redisCluster->lRange('y', 0, -1));
*
* ////Output:
* //
* //string(3) "abc"
* //array(1) {
* // [0]=>
* // string(3) "def"
* //}
* //array(3) {
* // [0]=>
* // string(3) "abc"
* // [1]=>
* // string(3) "456"
* // [2]=>
* // string(3) "123"
* //}
* </pre>
*/
public function rpoplpush($srcKey, $dstKey) {}
/**
* Returns the size of a list identified by Key. If the list didn't exist or is empty,
* the command returns 0. If the data type identified by Key is not a list, the command return FALSE.
*
* @param string $key
*
* @return int The size of the list identified by Key exists.
* bool FALSE if the data type identified by Key is not list
* @link https://redis.io/commands/llen
* @example
* <pre>
* $redisCluster->rPush('key1', 'A');
* $redisCluster->rPush('key1', 'B');
* $redisCluster->rPush('key1', 'C'); // key1 => [ 'A', 'B', 'C' ]
* $redisCluster->lLen('key1'); // 3
* $redisCluster->rPop('key1');
* $redisCluster->lLen('key1'); // 2
* </pre>
*/
public function lLen($key) {}
/**
* Returns the set cardinality (number of elements) of the set stored at key.
*
* @param string $key
*
* @return int the cardinality (number of elements) of the set, or 0 if key does not exist.
* @link https://redis.io/commands/scard
* @example
* <pre>
* $redisCluster->sAdd('key1' , 'set1');
* $redisCluster->sAdd('key1' , 'set2');
* $redisCluster->sAdd('key1' , 'set3'); // 'key1' => {'set1', 'set2', 'set3'}
* $redisCluster->sCard('key1'); // 3
* $redisCluster->sCard('keyX'); // 0
* </pre>
*/
public function sCard($key) {}
/**
* Returns all the members of the set value stored at key.
* This has the same effect as running SINTER with one argument key.
*
* @param string $key
*
* @return array All elements of the set.
* @link https://redis.io/commands/smembers
* @example
* <pre>
* $redisCluster->del('s');
* $redisCluster->sAdd('s', 'a');
* $redisCluster->sAdd('s', 'b');
* $redisCluster->sAdd('s', 'a');
* $redisCluster->sAdd('s', 'c');
* var_dump($redisCluster->sMembers('s'));
*
* ////Output:
* //
* //array(3) {
* // [0]=>
* // string(1) "b"
* // [1]=>
* // string(1) "c"
* // [2]=>
* // string(1) "a"
* //}
* // The order is random and corresponds to redis' own internal representation of the set structure.
* </pre>
*/
public function sMembers($key) {}
/**
* Returns if member is a member of the set stored at key.
*
* @param string $key
* @param string $value
*
* @return bool TRUE if value is a member of the set at key key, FALSE otherwise.
* @link https://redis.io/commands/sismember
* @example
* <pre>
* $redisCluster->sAdd('key1' , 'set1');
* $redisCluster->sAdd('key1' , 'set2');
* $redisCluster->sAdd('key1' , 'set3'); // 'key1' => {'set1', 'set2', 'set3'}
*
* $redisCluster->sIsMember('key1', 'set1'); // TRUE
* $redisCluster->sIsMember('key1', 'setX'); // FALSE
* </pre>
*/
public function sIsMember($key, $value) {}
/**
* Adds a values to the set value stored at key.
* If this value is already in the set, FALSE is returned.
*
* @param string $key Required key
* @param mixed $value1 Required value
* @param mixed $value2 Optional value
* @param mixed $valueN Optional value
*
* @return int|false The number of elements added to the set
* @link https://redis.io/commands/sadd
* @example
* <pre>
* $redisCluster->sAdd('k', 'v1'); // int(1)
* $redisCluster->sAdd('k', 'v1', 'v2', 'v3'); // int(2)
* </pre>
*/
public function sAdd($key, $value1, $value2 = null, $valueN = null) {}
/**
* Adds a values to the set value stored at key.
* If this value is already in the set, FALSE is returned.
*
* @param string $key Required key
* @param array $valueArray
*
* @return int|false The number of elements added to the set
* @example
* <pre>
* $redisCluster->sAddArray('k', ['v1', 'v2', 'v3']);
* //This is a feature in php only. Same as $redisCluster->sAdd('k', 'v1', 'v2', 'v3');
* </pre>
*/
public function sAddArray($key, array $valueArray) {}
/**
* Removes the specified members from the set value stored at key.
*
* @param string $key
* @param string $member1
* @param string $member2
* @param string $memberN
*
* @return int The number of elements removed from the set.
* @link https://redis.io/commands/srem
* @example
* <pre>
* var_dump( $redisCluster->sAdd('k', 'v1', 'v2', 'v3') ); // int(3)
* var_dump( $redisCluster->sRem('k', 'v2', 'v3') ); // int(2)
* var_dump( $redisCluster->sMembers('k') );
* //// Output:
* // array(1) {
* // [0]=> string(2) "v1"
* // }
* </pre>
*/
public function sRem($key, $member1, $member2 = null, $memberN = null) {}
/**
* Performs the union between N sets and returns it.
*
* @param string $key1 Any number of keys corresponding to sets in redis.
* @param string $key2 ...
* @param string $keyN ...
*
* @return array of strings: The union of all these sets.
* @link https://redis.io/commands/sunionstore
* @example
* <pre>
* $redisCluster->del('s0', 's1', 's2');
*
* $redisCluster->sAdd('s0', '1');
* $redisCluster->sAdd('s0', '2');
* $redisCluster->sAdd('s1', '3');
* $redisCluster->sAdd('s1', '1');
* $redisCluster->sAdd('s2', '3');
* $redisCluster->sAdd('s2', '4');
*
* var_dump($redisCluster->sUnion('s0', 's1', 's2'));
*
* //// Output:
* //
* //array(4) {
* // [0]=>
* // string(1) "3"
* // [1]=>
* // string(1) "4"
* // [2]=>
* // string(1) "1"
* // [3]=>
* // string(1) "2"
* //}
* </pre>
*/
public function sUnion($key1, $key2, $keyN = null) {}
/**
* Performs the same action as sUnion, but stores the result in the first key
*
* @param string $dstKey the key to store the diff into.
* @param string $key1 Any number of keys corresponding to sets in redis.
* @param string $key2 ...
* @param string $keyN ...
*
* @return int Any number of keys corresponding to sets in redis.
* @link https://redis.io/commands/sunionstore
* @example
* <pre>
* $redisCluster->del('s0', 's1', 's2');
*
* $redisCluster->sAdd('s0', '1');
* $redisCluster->sAdd('s0', '2');
* $redisCluster->sAdd('s1', '3');
* $redisCluster->sAdd('s1', '1');
* $redisCluster->sAdd('s2', '3');
* $redisCluster->sAdd('s2', '4');
*
* var_dump($redisCluster->sUnionStore('dst', 's0', 's1', 's2'));
* var_dump($redisCluster->sMembers('dst'));
*
* //// Output:
* //
* //int(4)
* //array(4) {
* // [0]=>