forked from phpredis/phpredis
-
Notifications
You must be signed in to change notification settings - Fork 0
/
redis_cluster.c
3241 lines (2732 loc) · 104 KB
/
redis_cluster.c
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
/*
+----------------------------------------------------------------------+
| Copyright (c) 1997-2009 The PHP Group |
+----------------------------------------------------------------------+
| This source file is subject to version 3.01 of the PHP license, |
| that is bundled with this package in the file LICENSE, and is |
| available through the world-wide-web at the following url: |
| http://www.php.net/license/3_01.txt |
| If you did not receive a copy of the PHP license and are unable to |
| obtain it through the world-wide-web, please send a note to |
| [email protected] so we can mail you a copy immediately. |
+----------------------------------------------------------------------+
| Author: Michael Grunder <[email protected]> |
| Maintainer: Nicolas Favre-Felix <[email protected]> |
+----------------------------------------------------------------------+
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include "common.h"
#include "php_redis.h"
#include "ext/standard/info.h"
#include "crc16.h"
#include "redis_cluster.h"
#include "redis_commands.h"
#include <zend_exceptions.h>
#include "library.h"
#include <php_variables.h>
#include <SAPI.h>
zend_class_entry *redis_cluster_ce;
/* Exception handler */
zend_class_entry *redis_cluster_exception_ce;
/* Handlers for RedisCluster */
zend_object_handlers RedisCluster_handlers;
ZEND_BEGIN_ARG_INFO_EX(arginfo_ctor, 0, 0, 1)
ZEND_ARG_INFO(0, name)
ZEND_ARG_ARRAY_INFO(0, seeds, 0)
ZEND_ARG_INFO(0, timeout)
ZEND_ARG_INFO(0, read_timeout)
ZEND_ARG_INFO(0, persistent)
ZEND_ARG_INFO(0, auth)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(arginfo_del, 0, 0, 1)
ZEND_ARG_INFO(0, key)
ZEND_ARG_VARIADIC_INFO(0, other_keys)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(arginfo_mget, 0, 0, 1)
ZEND_ARG_ARRAY_INFO(0, keys, 0)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(arginfo_keys, 0, 0, 1)
ZEND_ARG_INFO(0, pattern)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(arginfo_key_or_address, 0, 0, 1)
ZEND_ARG_INFO(0, key_or_address)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(arginfo_key_or_address_variadic, 0, 0, 1)
ZEND_ARG_INFO(0, key_or_address)
ZEND_ARG_INFO(0, arg)
ZEND_ARG_VARIADIC_INFO(0, other_args)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(arginfo_info, 0, 0, 1)
ZEND_ARG_INFO(0, key_or_address)
ZEND_ARG_INFO(0, option)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(arginfo_flush, 0, 0, 1)
ZEND_ARG_INFO(0, key_or_address)
ZEND_ARG_INFO(0, async)
ZEND_END_ARG_INFO()
/* Argument info for HSCAN, SSCAN, HSCAN */
ZEND_BEGIN_ARG_INFO_EX(arginfo_kscan_cl, 0, 0, 2)
ZEND_ARG_INFO(0, str_key)
ZEND_ARG_INFO(1, i_iterator)
ZEND_ARG_INFO(0, str_pattern)
ZEND_ARG_INFO(0, i_count)
ZEND_END_ARG_INFO()
/* Argument info for SCAN */
ZEND_BEGIN_ARG_INFO_EX(arginfo_scan_cl, 0, 0, 2)
ZEND_ARG_INFO(1, i_iterator)
ZEND_ARG_INFO(0, str_node)
ZEND_ARG_INFO(0, str_pattern)
ZEND_ARG_INFO(0, i_count)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(arginfo_acl_cl, 0, 0, 2)
ZEND_ARG_INFO(0, key_or_address)
ZEND_ARG_INFO(0, subcmd)
ZEND_ARG_VARIADIC_INFO(0, args)
ZEND_END_ARG_INFO()
/* Function table */
zend_function_entry redis_cluster_functions[] = {
PHP_ME(RedisCluster, __construct, arginfo_ctor, ZEND_ACC_PUBLIC)
PHP_ME(RedisCluster, _masters, arginfo_void, ZEND_ACC_PUBLIC)
PHP_ME(RedisCluster, _prefix, arginfo_key, ZEND_ACC_PUBLIC)
PHP_ME(RedisCluster, _redir, arginfo_void, ZEND_ACC_PUBLIC)
PHP_ME(RedisCluster, _serialize, arginfo_value, ZEND_ACC_PUBLIC)
PHP_ME(RedisCluster, _unserialize, arginfo_value, ZEND_ACC_PUBLIC)
PHP_ME(RedisCluster, acl, arginfo_acl_cl, ZEND_ACC_PUBLIC)
PHP_ME(RedisCluster, append, arginfo_key_value, ZEND_ACC_PUBLIC)
PHP_ME(RedisCluster, bgrewriteaof, arginfo_key_or_address, ZEND_ACC_PUBLIC)
PHP_ME(RedisCluster, bgsave, arginfo_key_or_address, ZEND_ACC_PUBLIC)
PHP_ME(RedisCluster, bitcount, arginfo_key, ZEND_ACC_PUBLIC)
PHP_ME(RedisCluster, bitop, arginfo_bitop, ZEND_ACC_PUBLIC)
PHP_ME(RedisCluster, bitpos, arginfo_bitpos, ZEND_ACC_PUBLIC)
PHP_ME(RedisCluster, blpop, arginfo_blrpop, ZEND_ACC_PUBLIC)
PHP_ME(RedisCluster, brpop, arginfo_blrpop, ZEND_ACC_PUBLIC)
PHP_ME(RedisCluster, brpoplpush, arginfo_brpoplpush, ZEND_ACC_PUBLIC)
PHP_ME(RedisCluster, clearlasterror, arginfo_void, ZEND_ACC_PUBLIC)
PHP_ME(RedisCluster, bzpopmax, arginfo_blrpop, ZEND_ACC_PUBLIC)
PHP_ME(RedisCluster, bzpopmin, arginfo_blrpop, ZEND_ACC_PUBLIC)
PHP_ME(RedisCluster, client, arginfo_key_or_address_variadic, ZEND_ACC_PUBLIC)
PHP_ME(RedisCluster, close, arginfo_void, ZEND_ACC_PUBLIC)
PHP_ME(RedisCluster, cluster, arginfo_key_or_address_variadic, ZEND_ACC_PUBLIC)
PHP_ME(RedisCluster, command, arginfo_command, ZEND_ACC_PUBLIC)
PHP_ME(RedisCluster, config, arginfo_key_or_address_variadic, ZEND_ACC_PUBLIC)
PHP_ME(RedisCluster, dbsize, arginfo_key_or_address, ZEND_ACC_PUBLIC)
PHP_ME(RedisCluster, decr, arginfo_key, ZEND_ACC_PUBLIC)
PHP_ME(RedisCluster, decrby, arginfo_key_value, ZEND_ACC_PUBLIC)
PHP_ME(RedisCluster, del, arginfo_del, ZEND_ACC_PUBLIC)
PHP_ME(RedisCluster, discard, arginfo_void, ZEND_ACC_PUBLIC)
PHP_ME(RedisCluster, dump, arginfo_key, ZEND_ACC_PUBLIC)
PHP_ME(RedisCluster, echo, arginfo_echo, ZEND_ACC_PUBLIC)
PHP_ME(RedisCluster, eval, arginfo_eval, ZEND_ACC_PUBLIC)
PHP_ME(RedisCluster, evalsha, arginfo_evalsha, ZEND_ACC_PUBLIC)
PHP_ME(RedisCluster, exec, arginfo_void, ZEND_ACC_PUBLIC)
PHP_ME(RedisCluster, exists, arginfo_key, ZEND_ACC_PUBLIC)
PHP_ME(RedisCluster, expire, arginfo_expire, ZEND_ACC_PUBLIC)
PHP_ME(RedisCluster, expireat, arginfo_key_timestamp, ZEND_ACC_PUBLIC)
PHP_ME(RedisCluster, flushall, arginfo_flush, ZEND_ACC_PUBLIC)
PHP_ME(RedisCluster, flushdb, arginfo_flush, ZEND_ACC_PUBLIC)
PHP_ME(RedisCluster, geoadd, arginfo_geoadd, ZEND_ACC_PUBLIC)
PHP_ME(RedisCluster, geodist, arginfo_geodist, ZEND_ACC_PUBLIC)
PHP_ME(RedisCluster, geohash, arginfo_key_members, ZEND_ACC_PUBLIC)
PHP_ME(RedisCluster, geopos, arginfo_key_members, ZEND_ACC_PUBLIC)
PHP_ME(RedisCluster, georadius, arginfo_georadius, ZEND_ACC_PUBLIC)
PHP_ME(RedisCluster, georadius_ro, arginfo_georadius, ZEND_ACC_PUBLIC)
PHP_ME(RedisCluster, georadiusbymember, arginfo_georadiusbymember, ZEND_ACC_PUBLIC)
PHP_ME(RedisCluster, georadiusbymember_ro, arginfo_georadiusbymember, ZEND_ACC_PUBLIC)
PHP_ME(RedisCluster, get, arginfo_key, ZEND_ACC_PUBLIC)
PHP_ME(RedisCluster, getbit, arginfo_key_offset, ZEND_ACC_PUBLIC)
PHP_ME(RedisCluster, getlasterror, arginfo_void, ZEND_ACC_PUBLIC)
PHP_ME(RedisCluster, getmode, arginfo_void, ZEND_ACC_PUBLIC)
PHP_ME(RedisCluster, getoption, arginfo_getoption, ZEND_ACC_PUBLIC)
PHP_ME(RedisCluster, getrange, arginfo_key_start_end, ZEND_ACC_PUBLIC)
PHP_ME(RedisCluster, getset, arginfo_key_value, ZEND_ACC_PUBLIC)
PHP_ME(RedisCluster, hdel, arginfo_key_members, ZEND_ACC_PUBLIC)
PHP_ME(RedisCluster, hexists, arginfo_key_member, ZEND_ACC_PUBLIC)
PHP_ME(RedisCluster, hget, arginfo_key_member, ZEND_ACC_PUBLIC)
PHP_ME(RedisCluster, hgetall, arginfo_key, ZEND_ACC_PUBLIC)
PHP_ME(RedisCluster, hincrby, arginfo_key_member_value, ZEND_ACC_PUBLIC)
PHP_ME(RedisCluster, hincrbyfloat, arginfo_key_member_value, ZEND_ACC_PUBLIC)
PHP_ME(RedisCluster, hkeys, arginfo_key, ZEND_ACC_PUBLIC)
PHP_ME(RedisCluster, hlen, arginfo_key, ZEND_ACC_PUBLIC)
PHP_ME(RedisCluster, hmget, arginfo_hmget, ZEND_ACC_PUBLIC)
PHP_ME(RedisCluster, hmset, arginfo_hmset, ZEND_ACC_PUBLIC)
PHP_ME(RedisCluster, hscan, arginfo_kscan_cl, ZEND_ACC_PUBLIC)
PHP_ME(RedisCluster, hset, arginfo_key_member_value, ZEND_ACC_PUBLIC)
PHP_ME(RedisCluster, hsetnx, arginfo_key_member_value, ZEND_ACC_PUBLIC)
PHP_ME(RedisCluster, hstrlen, arginfo_key_member, ZEND_ACC_PUBLIC)
PHP_ME(RedisCluster, hvals, arginfo_key, ZEND_ACC_PUBLIC)
PHP_ME(RedisCluster, incr, arginfo_key, ZEND_ACC_PUBLIC)
PHP_ME(RedisCluster, incrby, arginfo_key_value, ZEND_ACC_PUBLIC)
PHP_ME(RedisCluster, incrbyfloat, arginfo_key_value, ZEND_ACC_PUBLIC)
PHP_ME(RedisCluster, info, arginfo_info, ZEND_ACC_PUBLIC)
PHP_ME(RedisCluster, keys, arginfo_keys, ZEND_ACC_PUBLIC)
PHP_ME(RedisCluster, lastsave, arginfo_key_or_address, ZEND_ACC_PUBLIC)
PHP_ME(RedisCluster, lget, arginfo_lindex, ZEND_ACC_PUBLIC)
PHP_ME(RedisCluster, lindex, arginfo_lindex, ZEND_ACC_PUBLIC)
PHP_ME(RedisCluster, linsert, arginfo_linsert, ZEND_ACC_PUBLIC)
PHP_ME(RedisCluster, llen, arginfo_key, ZEND_ACC_PUBLIC)
PHP_ME(RedisCluster, lpop, arginfo_key, ZEND_ACC_PUBLIC)
PHP_ME(RedisCluster, lpush, arginfo_key_value, ZEND_ACC_PUBLIC)
PHP_ME(RedisCluster, lpushx, arginfo_key_value, ZEND_ACC_PUBLIC)
PHP_ME(RedisCluster, lrange, arginfo_key_start_end, ZEND_ACC_PUBLIC)
PHP_ME(RedisCluster, lrem, arginfo_key_value, ZEND_ACC_PUBLIC)
PHP_ME(RedisCluster, lset, arginfo_lset, ZEND_ACC_PUBLIC)
PHP_ME(RedisCluster, ltrim, arginfo_ltrim, ZEND_ACC_PUBLIC)
PHP_ME(RedisCluster, mget, arginfo_mget, ZEND_ACC_PUBLIC)
PHP_ME(RedisCluster, mset, arginfo_pairs, ZEND_ACC_PUBLIC)
PHP_ME(RedisCluster, msetnx, arginfo_pairs, ZEND_ACC_PUBLIC)
PHP_ME(RedisCluster, multi, arginfo_void, ZEND_ACC_PUBLIC)
PHP_ME(RedisCluster, object, arginfo_object, ZEND_ACC_PUBLIC)
PHP_ME(RedisCluster, persist, arginfo_key, ZEND_ACC_PUBLIC)
PHP_ME(RedisCluster, pexpire, arginfo_key_timestamp, ZEND_ACC_PUBLIC)
PHP_ME(RedisCluster, pexpireat, arginfo_key_timestamp, ZEND_ACC_PUBLIC)
PHP_ME(RedisCluster, pfadd, arginfo_pfadd, ZEND_ACC_PUBLIC)
PHP_ME(RedisCluster, pfcount, arginfo_key, ZEND_ACC_PUBLIC)
PHP_ME(RedisCluster, pfmerge, arginfo_pfmerge, ZEND_ACC_PUBLIC)
PHP_ME(RedisCluster, ping, arginfo_key_or_address, ZEND_ACC_PUBLIC)
PHP_ME(RedisCluster, psetex, arginfo_key_expire_value, ZEND_ACC_PUBLIC)
PHP_ME(RedisCluster, psubscribe, arginfo_psubscribe, ZEND_ACC_PUBLIC)
PHP_ME(RedisCluster, pttl, arginfo_key, ZEND_ACC_PUBLIC)
PHP_ME(RedisCluster, publish, arginfo_publish, ZEND_ACC_PUBLIC)
PHP_ME(RedisCluster, pubsub, arginfo_key_or_address_variadic, ZEND_ACC_PUBLIC)
PHP_ME(RedisCluster, punsubscribe, arginfo_punsubscribe, ZEND_ACC_PUBLIC)
PHP_ME(RedisCluster, randomkey, arginfo_key_or_address, ZEND_ACC_PUBLIC)
PHP_ME(RedisCluster, rawcommand, arginfo_rawcommand, ZEND_ACC_PUBLIC)
PHP_ME(RedisCluster, rename, arginfo_key_newkey, ZEND_ACC_PUBLIC)
PHP_ME(RedisCluster, renamenx, arginfo_key_newkey, ZEND_ACC_PUBLIC)
PHP_ME(RedisCluster, restore, arginfo_restore, ZEND_ACC_PUBLIC)
PHP_ME(RedisCluster, role, arginfo_void, ZEND_ACC_PUBLIC)
PHP_ME(RedisCluster, rpop, arginfo_key, ZEND_ACC_PUBLIC)
PHP_ME(RedisCluster, rpoplpush, arginfo_rpoplpush, ZEND_ACC_PUBLIC)
PHP_ME(RedisCluster, rpush, arginfo_key_value, ZEND_ACC_PUBLIC)
PHP_ME(RedisCluster, rpushx, arginfo_key_value, ZEND_ACC_PUBLIC)
PHP_ME(RedisCluster, sadd, arginfo_key_value, ZEND_ACC_PUBLIC)
PHP_ME(RedisCluster, saddarray, arginfo_sadd_array, ZEND_ACC_PUBLIC)
PHP_ME(RedisCluster, save, arginfo_key_or_address, ZEND_ACC_PUBLIC)
PHP_ME(RedisCluster, scan, arginfo_scan_cl, ZEND_ACC_PUBLIC)
PHP_ME(RedisCluster, scard, arginfo_key, ZEND_ACC_PUBLIC)
PHP_ME(RedisCluster, script, arginfo_key_or_address_variadic, ZEND_ACC_PUBLIC)
PHP_ME(RedisCluster, sdiff, arginfo_nkeys, ZEND_ACC_PUBLIC)
PHP_ME(RedisCluster, sdiffstore, arginfo_dst_nkeys, ZEND_ACC_PUBLIC)
PHP_ME(RedisCluster, set, arginfo_set, ZEND_ACC_PUBLIC)
PHP_ME(RedisCluster, setbit, arginfo_key_offset_value, ZEND_ACC_PUBLIC)
PHP_ME(RedisCluster, setex, arginfo_key_expire_value, ZEND_ACC_PUBLIC)
PHP_ME(RedisCluster, setnx, arginfo_key_value, ZEND_ACC_PUBLIC)
PHP_ME(RedisCluster, setoption, arginfo_setoption, ZEND_ACC_PUBLIC)
PHP_ME(RedisCluster, setrange, arginfo_key_offset_value, ZEND_ACC_PUBLIC)
PHP_ME(RedisCluster, sinter, arginfo_nkeys, ZEND_ACC_PUBLIC)
PHP_ME(RedisCluster, sinterstore, arginfo_dst_nkeys, ZEND_ACC_PUBLIC)
PHP_ME(RedisCluster, sismember, arginfo_key_value, ZEND_ACC_PUBLIC)
PHP_ME(RedisCluster, slowlog, arginfo_key_or_address_variadic, ZEND_ACC_PUBLIC)
PHP_ME(RedisCluster, smembers, arginfo_key, ZEND_ACC_PUBLIC)
PHP_ME(RedisCluster, smove, arginfo_smove, ZEND_ACC_PUBLIC)
PHP_ME(RedisCluster, sort, arginfo_sort, ZEND_ACC_PUBLIC)
PHP_ME(RedisCluster, spop, arginfo_key, ZEND_ACC_PUBLIC)
PHP_ME(RedisCluster, srandmember, arginfo_srand_member, ZEND_ACC_PUBLIC)
PHP_ME(RedisCluster, srem, arginfo_key_value, ZEND_ACC_PUBLIC)
PHP_ME(RedisCluster, sscan, arginfo_kscan_cl, ZEND_ACC_PUBLIC)
PHP_ME(RedisCluster, strlen, arginfo_key, ZEND_ACC_PUBLIC)
PHP_ME(RedisCluster, subscribe, arginfo_subscribe, ZEND_ACC_PUBLIC)
PHP_ME(RedisCluster, sunion, arginfo_nkeys, ZEND_ACC_PUBLIC)
PHP_ME(RedisCluster, sunionstore, arginfo_dst_nkeys, ZEND_ACC_PUBLIC)
PHP_ME(RedisCluster, time, arginfo_void, ZEND_ACC_PUBLIC)
PHP_ME(RedisCluster, ttl, arginfo_key, ZEND_ACC_PUBLIC)
PHP_ME(RedisCluster, type, arginfo_key, ZEND_ACC_PUBLIC)
PHP_ME(RedisCluster, unsubscribe, arginfo_unsubscribe, ZEND_ACC_PUBLIC)
PHP_ME(RedisCluster, unlink, arginfo_del, ZEND_ACC_PUBLIC)
PHP_ME(RedisCluster, unwatch, arginfo_void, ZEND_ACC_PUBLIC)
PHP_ME(RedisCluster, watch, arginfo_watch, ZEND_ACC_PUBLIC)
PHP_ME(RedisCluster, xack, arginfo_xack, ZEND_ACC_PUBLIC)
PHP_ME(RedisCluster, xadd, arginfo_xadd, ZEND_ACC_PUBLIC)
PHP_ME(RedisCluster, xclaim, arginfo_xclaim, ZEND_ACC_PUBLIC)
PHP_ME(RedisCluster, xdel, arginfo_xdel, ZEND_ACC_PUBLIC)
PHP_ME(RedisCluster, xgroup, arginfo_xgroup, ZEND_ACC_PUBLIC)
PHP_ME(RedisCluster, xinfo, arginfo_xinfo, ZEND_ACC_PUBLIC)
PHP_ME(RedisCluster, xlen, arginfo_key, ZEND_ACC_PUBLIC)
PHP_ME(RedisCluster, xpending, arginfo_xpending, ZEND_ACC_PUBLIC)
PHP_ME(RedisCluster, xrange, arginfo_xrange, ZEND_ACC_PUBLIC)
PHP_ME(RedisCluster, xread, arginfo_xread, ZEND_ACC_PUBLIC)
PHP_ME(RedisCluster, xreadgroup, arginfo_xreadgroup, ZEND_ACC_PUBLIC)
PHP_ME(RedisCluster, xrevrange, arginfo_xrange, ZEND_ACC_PUBLIC)
PHP_ME(RedisCluster, xtrim, arginfo_xtrim, ZEND_ACC_PUBLIC)
PHP_ME(RedisCluster, zadd, arginfo_zadd, ZEND_ACC_PUBLIC)
PHP_ME(RedisCluster, zcard, arginfo_key, ZEND_ACC_PUBLIC)
PHP_ME(RedisCluster, zcount, arginfo_key_min_max, ZEND_ACC_PUBLIC)
PHP_ME(RedisCluster, zincrby, arginfo_zincrby, ZEND_ACC_PUBLIC)
PHP_ME(RedisCluster, zinterstore, arginfo_zstore, ZEND_ACC_PUBLIC)
PHP_ME(RedisCluster, zlexcount, arginfo_key_min_max, ZEND_ACC_PUBLIC)
PHP_ME(RedisCluster, zpopmax, arginfo_key, ZEND_ACC_PUBLIC)
PHP_ME(RedisCluster, zpopmin, arginfo_key, ZEND_ACC_PUBLIC)
PHP_ME(RedisCluster, zrange, arginfo_zrange, ZEND_ACC_PUBLIC)
PHP_ME(RedisCluster, zrangebylex, arginfo_zrangebylex, ZEND_ACC_PUBLIC)
PHP_ME(RedisCluster, zrangebyscore, arginfo_zrangebyscore, ZEND_ACC_PUBLIC)
PHP_ME(RedisCluster, zrank, arginfo_key_member, ZEND_ACC_PUBLIC)
PHP_ME(RedisCluster, zrem, arginfo_key_members, ZEND_ACC_PUBLIC)
PHP_ME(RedisCluster, zremrangebylex, arginfo_key_min_max, ZEND_ACC_PUBLIC)
PHP_ME(RedisCluster, zremrangebyrank, arginfo_key_min_max, ZEND_ACC_PUBLIC)
PHP_ME(RedisCluster, zremrangebyscore, arginfo_key_min_max, ZEND_ACC_PUBLIC)
PHP_ME(RedisCluster, zrevrange, arginfo_zrange, ZEND_ACC_PUBLIC)
PHP_ME(RedisCluster, zrevrangebylex, arginfo_zrangebylex, ZEND_ACC_PUBLIC)
PHP_ME(RedisCluster, zrevrangebyscore, arginfo_zrangebyscore, ZEND_ACC_PUBLIC)
PHP_ME(RedisCluster, zrevrank, arginfo_key_member, ZEND_ACC_PUBLIC)
PHP_ME(RedisCluster, zscan, arginfo_kscan_cl, ZEND_ACC_PUBLIC)
PHP_ME(RedisCluster, zscore, arginfo_key_member, ZEND_ACC_PUBLIC)
PHP_ME(RedisCluster, zunionstore, arginfo_zstore, ZEND_ACC_PUBLIC)
PHP_FE_END
};
/* Our context seeds will be a hash table with RedisSock* pointers */
static void ht_free_seed(zval *data) {
RedisSock *redis_sock = *(RedisSock**)data;
if (redis_sock) redis_free_socket(redis_sock);
}
/* Free redisClusterNode objects we've stored */
static void ht_free_node(zval *data) {
redisClusterNode *node = *(redisClusterNode**)data;
cluster_free_node(node);
}
/* Create redisCluster context */
zend_object * create_cluster_context(zend_class_entry *class_type) {
redisCluster *cluster;
// Allocate our actual struct
cluster = ecalloc(1, sizeof(redisCluster) + zend_object_properties_size(class_type));
// We're not currently subscribed anywhere
cluster->subscribed_slot = -1;
// Allocate our RedisSock we'll use to store prefix/serialization flags
cluster->flags = ecalloc(1, sizeof(RedisSock));
// Allocate our hash table for seeds
ALLOC_HASHTABLE(cluster->seeds);
zend_hash_init(cluster->seeds, 0, NULL, ht_free_seed, 0);
// Allocate our hash table for connected Redis objects
ALLOC_HASHTABLE(cluster->nodes);
zend_hash_init(cluster->nodes, 0, NULL, ht_free_node, 0);
// Initialize it
zend_object_std_init(&cluster->std, class_type);
object_properties_init(&cluster->std, class_type);
memcpy(&RedisCluster_handlers, zend_get_std_object_handlers(), sizeof(RedisCluster_handlers));
RedisCluster_handlers.offset = XtOffsetOf(redisCluster, std);
RedisCluster_handlers.free_obj = free_cluster_context;
cluster->std.handlers = &RedisCluster_handlers;
return &cluster->std;
}
/* Free redisCluster context */
void free_cluster_context(zend_object *object) {
redisCluster *cluster = PHPREDIS_GET_OBJECT(redisCluster, object);
cluster_free(cluster, 0);
zend_object_std_dtor(&cluster->std);
}
/* Take user provided seeds and return unique and valid ones */
/* Attempt to connect to a Redis cluster provided seeds and timeout options */
static void redis_cluster_init(redisCluster *c, HashTable *ht_seeds, double timeout,
double read_timeout, int persistent, zend_string *user,
zend_string *pass, zval *context)
{
zend_string *hash = NULL, **seeds;
redisCachedCluster *cc;
uint32_t nseeds;
char *err;
/* Validate our arguments and get a sanitized seed array */
seeds = cluster_validate_args(timeout, read_timeout, ht_seeds, &nseeds, &err);
if (seeds == NULL) {
CLUSTER_THROW_EXCEPTION(err, 0);
return;
}
if (user && ZSTR_LEN(user))
c->flags->user = zend_string_copy(user);
if (pass && ZSTR_LEN(pass))
c->flags->pass = zend_string_copy(pass);
if (context) {
redis_sock_set_stream_context(c->flags, context);
}
c->flags->timeout = timeout;
c->flags->read_timeout = read_timeout;
c->flags->persistent = persistent;
c->waitms = timeout * 1000L;
/* Attempt to load slots from cache if caching is enabled */
if (CLUSTER_CACHING_ENABLED()) {
/* Exit early if we can load from cache */
hash = cluster_hash_seeds(seeds, nseeds);
if ((cc = cluster_cache_load(hash))) {
cluster_init_cache(c, cc);
goto cleanup;
}
}
/* Initialize seeds and attempt to map keyspace */
cluster_init_seeds(c, seeds, nseeds);
if (cluster_map_keyspace(c) == SUCCESS && hash)
cluster_cache_store(hash, c->nodes);
cleanup:
if (hash) zend_string_release(hash);
free_seed_array(seeds, nseeds);
}
/* Attempt to load a named cluster configured in php.ini */
void redis_cluster_load(redisCluster *c, char *name, int name_len) {
zval z_seeds, z_tmp, *z_value;
zend_string *user = NULL, *pass = NULL;
double timeout = 0, read_timeout = 0;
int persistent = 0;
char *iptr;
HashTable *ht_seeds = NULL;
/* Seeds */
array_init(&z_seeds);
if ((iptr = INI_STR("redis.clusters.seeds")) != NULL) {
sapi_module.treat_data(PARSE_STRING, estrdup(iptr), &z_seeds);
}
if ((z_value = zend_hash_str_find(Z_ARRVAL(z_seeds), name, name_len)) != NULL) {
ht_seeds = Z_ARRVAL_P(z_value);
} else {
zval_dtor(&z_seeds);
CLUSTER_THROW_EXCEPTION("Couldn't find seeds for cluster", 0);
return;
}
/* Connection timeout */
if ((iptr = INI_STR("redis.clusters.timeout")) != NULL) {
array_init(&z_tmp);
sapi_module.treat_data(PARSE_STRING, estrdup(iptr), &z_tmp);
redis_conf_double(Z_ARRVAL(z_tmp), name, name_len, &timeout);
zval_dtor(&z_tmp);
}
/* Read timeout */
if ((iptr = INI_STR("redis.clusters.read_timeout")) != NULL) {
array_init(&z_tmp);
sapi_module.treat_data(PARSE_STRING, estrdup(iptr), &z_tmp);
redis_conf_double(Z_ARRVAL(z_tmp), name, name_len, &read_timeout);
zval_dtor(&z_tmp);
}
/* Persistent connections */
if ((iptr = INI_STR("redis.clusters.persistent")) != NULL) {
array_init(&z_tmp);
sapi_module.treat_data(PARSE_STRING, estrdup(iptr), &z_tmp);
redis_conf_bool(Z_ARRVAL(z_tmp), name, name_len, &persistent);
zval_dtor(&z_tmp);
}
if ((iptr = INI_STR("redis.clusters.auth"))) {
array_init(&z_tmp);
sapi_module.treat_data(PARSE_STRING, estrdup(iptr), &z_tmp);
redis_conf_auth(Z_ARRVAL(z_tmp), name, name_len, &user, &pass);
zval_dtor(&z_tmp);
}
/* Attempt to create/connect to the cluster */
redis_cluster_init(c, ht_seeds, timeout, read_timeout, persistent, user, pass, NULL);
/* Clean up */
zval_dtor(&z_seeds);
if (user) zend_string_release(user);
if (pass) zend_string_release(pass);
}
/*
* PHP Methods
*/
/* Create a RedisCluster Object */
PHP_METHOD(RedisCluster, __construct) {
zval *object, *z_seeds = NULL, *z_auth = NULL, *context = NULL;
zend_string *user = NULL, *pass = NULL;
double timeout = 0.0, read_timeout = 0.0;
size_t name_len;
zend_bool persistent = 0;
redisCluster *c = GET_CONTEXT();
char *name;
// Parse arguments
if (zend_parse_method_parameters(ZEND_NUM_ARGS(), getThis(),
"Os!|addbza", &object, redis_cluster_ce, &name,
&name_len, &z_seeds, &timeout, &read_timeout,
&persistent, &z_auth, &context) == FAILURE)
{
RETURN_FALSE;
}
/* If we've got a string try to load from INI */
if (ZEND_NUM_ARGS() < 2) {
if (name_len == 0) { // Require a name
CLUSTER_THROW_EXCEPTION("You must specify a name or pass seeds!", 0);
}
redis_cluster_load(c, name, name_len);
return;
}
/* The normal case, loading from arguments */
redis_extract_auth_info(z_auth, &user, &pass);
redis_cluster_init(c, Z_ARRVAL_P(z_seeds), timeout, read_timeout,
persistent, user, pass, context);
if (user) zend_string_release(user);
if (pass) zend_string_release(pass);
}
/*
* RedisCluster method implementation
*/
/* {{{ proto bool RedisCluster::close() */
PHP_METHOD(RedisCluster, close) {
cluster_disconnect(GET_CONTEXT(), 1);
RETURN_TRUE;
}
/* {{{ proto string RedisCluster::get(string key) */
PHP_METHOD(RedisCluster, get) {
CLUSTER_PROCESS_KW_CMD("GET", redis_key_cmd, cluster_bulk_resp, 1);
}
/* }}} */
/* {{{ proto bool RedisCluster::set(string key, string value) */
PHP_METHOD(RedisCluster, set) {
CLUSTER_PROCESS_CMD(set, cluster_bool_resp, 0);
}
/* }}} */
/* Generic handler for MGET/MSET/MSETNX */
static int
distcmd_resp_handler(INTERNAL_FUNCTION_PARAMETERS, redisCluster *c, short slot,
clusterMultiCmd *mc, zval *z_ret, int last, cluster_cb cb)
{
clusterMultiCtx *ctx;
// Finalize multi command
cluster_multi_fini(mc);
// Spin up multi context
ctx = emalloc(sizeof(clusterMultiCtx));
ctx->z_multi = z_ret;
ctx->count = mc->argc;
ctx->last = last;
// Attempt to send the command
if (cluster_send_command(c,slot,mc->cmd.c,mc->cmd.len) < 0 || c->err != NULL) {
efree(ctx);
return -1;
}
if (CLUSTER_IS_ATOMIC(c)) {
// Process response now
cb(INTERNAL_FUNCTION_PARAM_PASSTHRU, c, (void*)ctx);
} else {
CLUSTER_ENQUEUE_RESPONSE(c, slot, cb, ctx);
}
// Clear out our command but retain allocated memory
CLUSTER_MULTI_CLEAR(mc);
return 0;
}
/* Container struct for a key/value pair pulled from an array */
typedef struct clusterKeyValHT {
char kbuf[22];
char *key;
size_t key_len;
int key_free;
short slot;
char *val;
size_t val_len;
int val_free;
} clusterKeyValHT;
/* Helper to pull a key/value pair from a HashTable */
static int get_key_val_ht(redisCluster *c, HashTable *ht, HashPosition *ptr,
clusterKeyValHT *kv)
{
zval *z_val;
zend_ulong idx;
// Grab the key, convert it to a string using provided kbuf buffer if it's
// a LONG style key
zend_string *zkey;
switch (zend_hash_get_current_key_ex(ht, &zkey, &idx, ptr)) {
case HASH_KEY_IS_STRING:
kv->key_len = ZSTR_LEN(zkey);
kv->key = ZSTR_VAL(zkey);
break;
case HASH_KEY_IS_LONG:
kv->key_len = snprintf(kv->kbuf,sizeof(kv->kbuf),"%ld",(long)idx);
kv->key = kv->kbuf;
break;
default:
CLUSTER_THROW_EXCEPTION("Internal Zend HashTable error", 0);
return -1;
}
// Prefix our key if we need to, set the slot
kv->key_free = redis_key_prefix(c->flags, &(kv->key), &(kv->key_len));
kv->slot = cluster_hash_key(kv->key, kv->key_len);
// Now grab our value
if ((z_val = zend_hash_get_current_data_ex(ht, ptr)) == NULL) {
CLUSTER_THROW_EXCEPTION("Internal Zend HashTable error", 0);
return -1;
}
// Serialize our value if required
kv->val_free = redis_pack(c->flags,z_val,&(kv->val),&(kv->val_len));
// Success
return 0;
}
/* Helper to pull, prefix, and hash a key from a HashTable value */
static int get_key_ht(redisCluster *c, HashTable *ht, HashPosition *ptr,
clusterKeyValHT *kv)
{
zval *z_key;
if ((z_key = zend_hash_get_current_data_ex(ht, ptr)) == NULL) {
// Shouldn't happen, but check anyway
CLUSTER_THROW_EXCEPTION("Internal Zend HashTable error", 0);
return -1;
}
// Always want to work with strings
convert_to_string(z_key);
kv->key = Z_STRVAL_P(z_key);
kv->key_len = Z_STRLEN_P(z_key);
kv->key_free = redis_key_prefix(c->flags, &(kv->key), &(kv->key_len));
// Hash our key
kv->slot = cluster_hash_key(kv->key, kv->key_len);
// Success
return 0;
}
/* Turn variable arguments into a HashTable for processing */
static HashTable *method_args_to_ht(zval *z_args, int argc) {
HashTable *ht_ret;
int i;
/* Allocate our hash table */
ALLOC_HASHTABLE(ht_ret);
zend_hash_init(ht_ret, argc, NULL, NULL, 0);
/* Populate our return hash table with our arguments */
for (i = 0; i < argc; i++) {
zend_hash_next_index_insert(ht_ret, &z_args[i]);
}
/* Return our hash table */
return ht_ret;
}
/* Convenience handler for commands that take multiple keys such as
* MGET, DEL, and UNLINK */
static int cluster_mkey_cmd(INTERNAL_FUNCTION_PARAMETERS, char *kw, int kw_len,
zval *z_ret, cluster_cb cb)
{
redisCluster *c = GET_CONTEXT();
clusterMultiCmd mc = {0};
clusterKeyValHT kv;
zval *z_args;
HashTable *ht_arr;
HashPosition ptr;
int i = 1, argc = ZEND_NUM_ARGS(), ht_free = 0;
short slot;
/* If we don't have any arguments we're invalid */
if (!argc) return -1;
/* Extract our arguments into an array */
z_args = ecalloc(argc, sizeof(zval));
if (zend_get_parameters_array(ht, argc, z_args) == FAILURE) {
efree(z_args);
return -1;
}
/* Determine if we're working with a single array or variadic args */
if (argc == 1 && Z_TYPE(z_args[0]) == IS_ARRAY) {
ht_arr = Z_ARRVAL(z_args[0]);
argc = zend_hash_num_elements(ht_arr);
if (!argc) {
efree(z_args);
return -1;
}
} else {
ht_arr = method_args_to_ht(z_args, argc);
ht_free = 1;
}
/* MGET is readonly, DEL is not */
c->readonly = kw_len == 4 && CLUSTER_IS_ATOMIC(c);
// Initialize our "multi" command handler with command/len
CLUSTER_MULTI_INIT(mc, kw, kw_len);
// Process the first key outside of our loop, so we don't have to check if
// it's the first iteration every time, needlessly
zend_hash_internal_pointer_reset_ex(ht_arr, &ptr);
if (get_key_ht(c, ht_arr, &ptr, &kv) < 0) {
efree(z_args);
return -1;
}
// Process our key and add it to the command
cluster_multi_add(&mc, kv.key, kv.key_len);
// Free key if we prefixed
if (kv.key_free) efree(kv.key);
// Move to the next key
zend_hash_move_forward_ex(ht_arr, &ptr);
// Iterate over keys 2...N
slot = kv.slot;
while (zend_hash_has_more_elements_ex(ht_arr, &ptr) ==SUCCESS) {
if (get_key_ht(c, ht_arr, &ptr, &kv) < 0) {
cluster_multi_free(&mc);
if (ht_free) {
zend_hash_destroy(ht_arr);
efree(ht_arr);
}
efree(z_args);
return -1;
}
// If the slots have changed, kick off the keys we've aggregated
if (slot != kv.slot) {
// Process this batch of MGET keys
if (distcmd_resp_handler(INTERNAL_FUNCTION_PARAM_PASSTHRU, c, slot,
&mc, z_ret, i == argc, cb) < 0)
{
cluster_multi_free(&mc);
if (ht_free) {
zend_hash_destroy(ht_arr);
efree(ht_arr);
}
efree(z_args);
return -1;
}
}
// Add this key to the command
cluster_multi_add(&mc, kv.key, kv.key_len);
// Free key if we prefixed
if (kv.key_free) efree(kv.key);
// Update the last slot we encountered, and the key we're on
slot = kv.slot;
i++;
zend_hash_move_forward_ex(ht_arr, &ptr);
}
efree(z_args);
// If we've got straggler(s) process them
if (mc.argc > 0) {
if (distcmd_resp_handler(INTERNAL_FUNCTION_PARAM_PASSTHRU, c, slot,
&mc, z_ret, 1, cb) < 0)
{
cluster_multi_free(&mc);
if (ht_free) {
zend_hash_destroy(ht_arr);
efree(ht_arr);
}
return -1;
}
}
// Free our command
cluster_multi_free(&mc);
/* Clean up our hash table if we constructed it from variadic args */
if (ht_free) {
zend_hash_destroy(ht_arr);
efree(ht_arr);
}
/* Return our object if we're in MULTI mode */
if (!CLUSTER_IS_ATOMIC(c))
RETVAL_ZVAL(getThis(), 1, 0);
// Success
return 0;
}
/* Handler for both MSET and MSETNX */
static int cluster_mset_cmd(INTERNAL_FUNCTION_PARAMETERS, char *kw, int kw_len,
zval *z_ret, cluster_cb cb)
{
redisCluster *c = GET_CONTEXT();
clusterKeyValHT kv;
clusterMultiCmd mc = {0};
zval *z_arr;
HashTable *ht_arr;
HashPosition ptr;
int i = 1, argc;
short slot;
// Parse our arguments
if (zend_parse_parameters(ZEND_NUM_ARGS(), "a", &z_arr) == FAILURE) {
return -1;
}
// No reason to send zero args
ht_arr = Z_ARRVAL_P(z_arr);
if ((argc = zend_hash_num_elements(ht_arr)) == 0) {
return -1;
}
/* This is a write command */
c->readonly = 0;
// Set up our multi command handler
CLUSTER_MULTI_INIT(mc, kw, kw_len);
// Process the first key/value pair outside of our loop
zend_hash_internal_pointer_reset_ex(ht_arr, &ptr);
if (get_key_val_ht(c, ht_arr, &ptr, &kv) ==-1) return -1;
zend_hash_move_forward_ex(ht_arr, &ptr);
// Add this to our multi cmd, set slot, free key if we prefixed
cluster_multi_add(&mc, kv.key, kv.key_len);
cluster_multi_add(&mc, kv.val, kv.val_len);
if (kv.key_free) efree(kv.key);
if (kv.val_free) efree(kv.val);
// While we've got more keys to set
slot = kv.slot;
while (zend_hash_has_more_elements_ex(ht_arr, &ptr) ==SUCCESS) {
// Pull the next key/value pair
if (get_key_val_ht(c, ht_arr, &ptr, &kv) ==-1) {
return -1;
}
// If the slots have changed, process responses
if (slot != kv.slot) {
if (distcmd_resp_handler(INTERNAL_FUNCTION_PARAM_PASSTHRU, c,
slot, &mc, z_ret, i == argc, cb) < 0)
{
cluster_multi_free(&mc);
return -1;
}
}
// Add this key and value to our command
cluster_multi_add(&mc, kv.key, kv.key_len);
cluster_multi_add(&mc, kv.val, kv.val_len);
// Free our key and value if we need to
if (kv.key_free) efree(kv.key);
if (kv.val_free) efree(kv.val);
// Update our slot, increment position
slot = kv.slot;
i++;
// Move on
zend_hash_move_forward_ex(ht_arr, &ptr);
}
// If we've got stragglers, process them too
if (mc.argc > 0) {
if (distcmd_resp_handler(INTERNAL_FUNCTION_PARAM_PASSTHRU, c, slot, &mc,
z_ret, 1, cb) < 0)
{
cluster_multi_free(&mc);
return -1;
}
}
// Free our command
cluster_multi_free(&mc);
/* Return our object if we're in MULTI mode */
if (!CLUSTER_IS_ATOMIC(c))
RETVAL_ZVAL(getThis(), 1, 0);
// Success
return 0;
}
/* Generic passthru for DEL and UNLINK which act identically */
static void cluster_generic_delete(INTERNAL_FUNCTION_PARAMETERS,
char *kw, int kw_len)
{
zval *z_ret = emalloc(sizeof(*z_ret));
// Initialize a LONG value to zero for our return
ZVAL_LONG(z_ret, 0);
// Parse args, process
if (cluster_mkey_cmd(INTERNAL_FUNCTION_PARAM_PASSTHRU, kw, kw_len, z_ret,
cluster_del_resp) < 0)
{
efree(z_ret);
RETURN_FALSE;
}
}
/* {{{ proto array RedisCluster::del(string key1, string key2, ... keyN) */
PHP_METHOD(RedisCluster, del) {
cluster_generic_delete(INTERNAL_FUNCTION_PARAM_PASSTHRU, "DEL", sizeof("DEL") - 1);
}
/* {{{ proto array RedisCluster::unlink(string key1, string key2, ... keyN) */
PHP_METHOD(RedisCluster, unlink) {
cluster_generic_delete(INTERNAL_FUNCTION_PARAM_PASSTHRU, "UNLINK", sizeof("UNLINK") - 1);
}
/* {{{ proto array RedisCluster::mget(array keys) */
PHP_METHOD(RedisCluster, mget) {
zval *z_ret = emalloc(sizeof(*z_ret));
array_init(z_ret);
// Parse args, process
if (cluster_mkey_cmd(INTERNAL_FUNCTION_PARAM_PASSTHRU, "MGET",
sizeof("MGET")-1, z_ret, cluster_mbulk_mget_resp) < 0)
{
zval_dtor(z_ret);
efree(z_ret);
RETURN_FALSE;
}
}
/* {{{ proto bool RedisCluster::mset(array keyvalues) */
PHP_METHOD(RedisCluster, mset) {
zval *z_ret = emalloc(sizeof(*z_ret));
ZVAL_TRUE(z_ret);
// Parse args and process. If we get a failure, free zval and return FALSE.
if (cluster_mset_cmd(INTERNAL_FUNCTION_PARAM_PASSTHRU, "MSET",
sizeof("MSET")-1, z_ret, cluster_mset_resp) ==-1)
{
efree(z_ret);
RETURN_FALSE;
}
}
/* {{{ proto array RedisCluster::msetnx(array keyvalues) */
PHP_METHOD(RedisCluster, msetnx) {
zval *z_ret = emalloc(sizeof(*z_ret));
array_init(z_ret);
// Parse args and process. If we get a failure, free mem and return FALSE
if (cluster_mset_cmd(INTERNAL_FUNCTION_PARAM_PASSTHRU, "MSETNX",
sizeof("MSETNX")-1, z_ret, cluster_msetnx_resp) ==-1)
{
zval_dtor(z_ret);
efree(z_ret);
RETURN_FALSE;
}
}
/* }}} */
/* {{{ proto bool RedisCluster::setex(string key, string value, int expiry) */
PHP_METHOD(RedisCluster, setex) {
CLUSTER_PROCESS_KW_CMD("SETEX", redis_key_long_val_cmd, cluster_bool_resp, 0);
}
/* }}} */
/* {{{ proto bool RedisCluster::psetex(string key, string value, int expiry) */
PHP_METHOD(RedisCluster, psetex) {
CLUSTER_PROCESS_KW_CMD("PSETEX", redis_key_long_val_cmd, cluster_bool_resp, 0);
}
/* }}} */
/* {{{ proto bool RedisCluster::setnx(string key, string value) */
PHP_METHOD(RedisCluster, setnx) {
CLUSTER_PROCESS_KW_CMD("SETNX", redis_kv_cmd, cluster_1_resp, 0);
}
/* }}} */
/* {{{ proto string RedisCluster::getSet(string key, string value) */
PHP_METHOD(RedisCluster, getset) {
CLUSTER_PROCESS_KW_CMD("GETSET", redis_kv_cmd, cluster_bulk_resp, 0);
}
/* }}} */
/* {{{ proto int RedisCluster::exists(string key) */
PHP_METHOD(RedisCluster, exists) {
CLUSTER_PROCESS_CMD(exists, cluster_long_resp, 1);
}
/* }}} */
/* {{{ proto array Redis::keys(string pattern) */
PHP_METHOD(RedisCluster, keys) {
redisCluster *c = GET_CONTEXT();
redisClusterNode *node;