forked from phpredis/phpredis
-
Notifications
You must be signed in to change notification settings - Fork 0
/
redis.c
3571 lines (3076 loc) · 109 KB
/
redis.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
/* -*- Mode: C; tab-width: 4 -*- */
/*
+----------------------------------------------------------------------+
| PHP Version 5 |
+----------------------------------------------------------------------+
| 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 |
| license@php.net so we can mail you a copy immediately. |
+----------------------------------------------------------------------+
| Original author: Alfonso Jimenez <yo@alfonsojimenez.com> |
| Maintainer: Nicolas Favre-Felix <n.favre-felix@owlient.eu> |
| Maintainer: Nasreddine Bouafif <n.bouafif@owlient.eu> |
| Maintainer: Michael Grunder <michael.grunder@gmail.com> |
+----------------------------------------------------------------------+
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include "common.h"
#include "ext/standard/info.h"
#include "php_redis.h"
#include "redis_commands.h"
#include "redis_array.h"
#include "redis_cluster.h"
#include <zend_exceptions.h>
#ifdef PHP_SESSION
#include "ext/session/php_session.h"
#endif
#include "library.h"
#ifdef PHP_SESSION
extern ps_module ps_mod_redis;
extern ps_module ps_mod_redis_cluster;
#endif
extern zend_class_entry *redis_array_ce;
extern zend_class_entry *redis_cluster_ce;
extern zend_class_entry *redis_cluster_exception_ce;
zend_class_entry *redis_ce;
zend_class_entry *redis_exception_ce;
extern zend_function_entry redis_array_functions[];
extern zend_function_entry redis_cluster_functions[];
PHP_INI_BEGIN()
/* redis arrays */
PHP_INI_ENTRY("redis.arrays.autorehash", "", PHP_INI_ALL, NULL)
PHP_INI_ENTRY("redis.arrays.connecttimeout", "", PHP_INI_ALL, NULL)
PHP_INI_ENTRY("redis.arrays.distributor", "", PHP_INI_ALL, NULL)
PHP_INI_ENTRY("redis.arrays.functions", "", PHP_INI_ALL, NULL)
PHP_INI_ENTRY("redis.arrays.hosts", "", PHP_INI_ALL, NULL)
PHP_INI_ENTRY("redis.arrays.index", "", PHP_INI_ALL, NULL)
PHP_INI_ENTRY("redis.arrays.lazyconnect", "", PHP_INI_ALL, NULL)
PHP_INI_ENTRY("redis.arrays.names", "", PHP_INI_ALL, NULL)
PHP_INI_ENTRY("redis.arrays.pconnect", "", PHP_INI_ALL, NULL)
PHP_INI_ENTRY("redis.arrays.previous", "", PHP_INI_ALL, NULL)
PHP_INI_ENTRY("redis.arrays.readtimeout", "", PHP_INI_ALL, NULL)
PHP_INI_ENTRY("redis.arrays.retryinterval", "", PHP_INI_ALL, NULL)
/* redis cluster */
PHP_INI_ENTRY("redis.clusters.persistent", "", PHP_INI_ALL, NULL)
PHP_INI_ENTRY("redis.clusters.read_timeout", "", PHP_INI_ALL, NULL)
PHP_INI_ENTRY("redis.clusters.seeds", "", PHP_INI_ALL, NULL)
PHP_INI_ENTRY("redis.clusters.timeout", "", PHP_INI_ALL, NULL)
/* redis session */
PHP_INI_ENTRY("redis.session.locking_enabled", "", PHP_INI_ALL, NULL)
PHP_INI_ENTRY("redis.session.lock_expire", "", PHP_INI_ALL, NULL)
PHP_INI_ENTRY("redis.session.lock_retries", "", PHP_INI_ALL, NULL)
PHP_INI_ENTRY("redis.session.lock_wait_time", "", PHP_INI_ALL, NULL)
PHP_INI_END()
/** {{{ Argument info for commands in redis 1.0 */
ZEND_BEGIN_ARG_INFO_EX(arginfo_connect, 0, 0, 1)
ZEND_ARG_INFO(0, host)
ZEND_ARG_INFO(0, port)
ZEND_ARG_INFO(0, timeout)
ZEND_ARG_INFO(0, retry_interval)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(arginfo_info, 0, 0, 0)
ZEND_ARG_INFO(0, option)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(arginfo_client, 0, 0, 1)
ZEND_ARG_INFO(0, cmd)
#if PHP_VERSION_ID >= 50600
ZEND_ARG_VARIADIC_INFO(0, args)
#else
ZEND_ARG_INFO(0, ...)
#endif
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(arginfo_config, 0, 0, 2)
ZEND_ARG_INFO(0, cmd)
ZEND_ARG_INFO(0, key)
ZEND_ARG_INFO(0, value)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(arginfo_flush, 0, 0, 0)
ZEND_ARG_INFO(0, async)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(arginfo_pubsub, 0, 0, 1)
ZEND_ARG_INFO(0, cmd)
#if PHP_VERSION_ID >= 50600
ZEND_ARG_VARIADIC_INFO(0, args)
#else
ZEND_ARG_INFO(0, ...)
#endif
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(arginfo_slowlog, 0, 0, 1)
ZEND_ARG_INFO(0, arg)
ZEND_ARG_INFO(0, option)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(arginfo_pconnect, 0, 0, 1)
ZEND_ARG_INFO(0, host)
ZEND_ARG_INFO(0, port)
ZEND_ARG_INFO(0, timeout)
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_exists, 0, 0, 1)
ZEND_ARG_INFO(0, key)
#if PHP_VERSION_ID >= 50600
ZEND_ARG_VARIADIC_INFO(0, other_keys)
#else
ZEND_ARG_INFO(0, ...)
#endif
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(arginfo_del, 0, 0, 1)
ZEND_ARG_INFO(0, key)
#if PHP_VERSION_ID >= 50600
ZEND_ARG_VARIADIC_INFO(0, other_keys)
#else
ZEND_ARG_INFO(0, ...)
#endif
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_generic_sort, 0, 0, 1)
ZEND_ARG_INFO(0, key)
ZEND_ARG_INFO(0, pattern)
ZEND_ARG_INFO(0, get)
ZEND_ARG_INFO(0, start)
ZEND_ARG_INFO(0, end)
ZEND_ARG_INFO(0, getList)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(arginfo_lrem, 0, 0, 3)
ZEND_ARG_INFO(0, key)
ZEND_ARG_INFO(0, value)
ZEND_ARG_INFO(0, count)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(arginfo_auth, 0, 0, 1)
ZEND_ARG_INFO(0, password)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(arginfo_select, 0, 0, 1)
ZEND_ARG_INFO(0, dbindex)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(arginfo_move, 0, 0, 2)
ZEND_ARG_INFO(0, key)
ZEND_ARG_INFO(0, dbindex)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(arginfo_slaveof, 0, 0, 0)
ZEND_ARG_INFO(0, host)
ZEND_ARG_INFO(0, port)
ZEND_END_ARG_INFO()
/* }}} */
ZEND_BEGIN_ARG_INFO_EX(arginfo_migrate, 0, 0, 5)
ZEND_ARG_INFO(0, host)
ZEND_ARG_INFO(0, port)
ZEND_ARG_INFO(0, key)
ZEND_ARG_INFO(0, db)
ZEND_ARG_INFO(0, timeout)
ZEND_ARG_INFO(0, copy)
ZEND_ARG_INFO(0, replace)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(arginfo_wait, 0, 0, 2)
ZEND_ARG_INFO(0, numslaves)
ZEND_ARG_INFO(0, timeout)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(arginfo_script, 0, 0, 1)
ZEND_ARG_INFO(0, cmd)
#if PHP_VERSION_ID >= 50600
ZEND_ARG_VARIADIC_INFO(0, args)
#else
ZEND_ARG_INFO(0, ...)
#endif
ZEND_END_ARG_INFO()
/**
* Argument info for the SCAN proper
*/
ZEND_BEGIN_ARG_INFO_EX(arginfo_scan, 0, 0, 1)
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 key scanning
*/
ZEND_BEGIN_ARG_INFO_EX(arginfo_kscan, 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()
static zend_function_entry redis_functions[] = {
PHP_ME(Redis, __construct, arginfo_void, ZEND_ACC_CTOR | ZEND_ACC_PUBLIC)
PHP_ME(Redis, __destruct, arginfo_void, ZEND_ACC_DTOR | ZEND_ACC_PUBLIC)
PHP_ME(Redis, _prefix, arginfo_key, ZEND_ACC_PUBLIC)
PHP_ME(Redis, _serialize, arginfo_value, ZEND_ACC_PUBLIC)
PHP_ME(Redis, _unserialize, arginfo_value, ZEND_ACC_PUBLIC)
PHP_ME(Redis, append, arginfo_key_value, ZEND_ACC_PUBLIC)
PHP_ME(Redis, auth, arginfo_auth, ZEND_ACC_PUBLIC)
PHP_ME(Redis, bgSave, arginfo_void, ZEND_ACC_PUBLIC)
PHP_ME(Redis, bgrewriteaof, arginfo_void, ZEND_ACC_PUBLIC)
PHP_ME(Redis, bitcount, arginfo_key, ZEND_ACC_PUBLIC)
PHP_ME(Redis, bitop, arginfo_bitop, ZEND_ACC_PUBLIC)
PHP_ME(Redis, bitpos, arginfo_bitpos, ZEND_ACC_PUBLIC)
PHP_ME(Redis, blPop, arginfo_blrpop, ZEND_ACC_PUBLIC)
PHP_ME(Redis, brPop, arginfo_blrpop, ZEND_ACC_PUBLIC)
PHP_ME(Redis, brpoplpush, arginfo_brpoplpush, ZEND_ACC_PUBLIC)
PHP_ME(Redis, clearLastError, arginfo_void, ZEND_ACC_PUBLIC)
PHP_ME(Redis, client, arginfo_client, ZEND_ACC_PUBLIC)
PHP_ME(Redis, close, arginfo_void, ZEND_ACC_PUBLIC)
PHP_ME(Redis, command, arginfo_command, ZEND_ACC_PUBLIC)
PHP_ME(Redis, config, arginfo_config, ZEND_ACC_PUBLIC)
PHP_ME(Redis, connect, arginfo_connect, ZEND_ACC_PUBLIC)
PHP_ME(Redis, dbSize, arginfo_void, ZEND_ACC_PUBLIC)
PHP_ME(Redis, debug, arginfo_key, ZEND_ACC_PUBLIC)
PHP_ME(Redis, decr, arginfo_key, ZEND_ACC_PUBLIC)
PHP_ME(Redis, decrBy, arginfo_key_value, ZEND_ACC_PUBLIC)
PHP_ME(Redis, delete, arginfo_del, ZEND_ACC_PUBLIC)
PHP_ME(Redis, discard, arginfo_void, ZEND_ACC_PUBLIC)
PHP_ME(Redis, dump, arginfo_key, ZEND_ACC_PUBLIC)
PHP_ME(Redis, echo, arginfo_echo, ZEND_ACC_PUBLIC)
PHP_ME(Redis, eval, arginfo_eval, ZEND_ACC_PUBLIC)
PHP_ME(Redis, evalsha, arginfo_evalsha, ZEND_ACC_PUBLIC)
PHP_ME(Redis, exec, arginfo_void, ZEND_ACC_PUBLIC)
PHP_ME(Redis, exists, arginfo_exists, ZEND_ACC_PUBLIC)
PHP_ME(Redis, expireAt, arginfo_key_timestamp, ZEND_ACC_PUBLIC)
PHP_ME(Redis, flushAll, arginfo_flush, ZEND_ACC_PUBLIC)
PHP_ME(Redis, flushDB, arginfo_flush, ZEND_ACC_PUBLIC)
PHP_ME(Redis, geoadd, arginfo_geoadd, ZEND_ACC_PUBLIC)
PHP_ME(Redis, geodist, arginfo_geodist, ZEND_ACC_PUBLIC)
PHP_ME(Redis, geohash, arginfo_key_members, ZEND_ACC_PUBLIC)
PHP_ME(Redis, geopos, arginfo_key_members, ZEND_ACC_PUBLIC)
PHP_ME(Redis, georadius, arginfo_georadius, ZEND_ACC_PUBLIC)
PHP_ME(Redis, georadiusbymember, arginfo_georadiusbymember, ZEND_ACC_PUBLIC)
PHP_ME(Redis, get, arginfo_key, ZEND_ACC_PUBLIC)
PHP_ME(Redis, getAuth, arginfo_void, ZEND_ACC_PUBLIC)
PHP_ME(Redis, getBit, arginfo_key_offset, ZEND_ACC_PUBLIC)
PHP_ME(Redis, getDBNum, arginfo_void, ZEND_ACC_PUBLIC)
PHP_ME(Redis, getHost, arginfo_void, ZEND_ACC_PUBLIC)
PHP_ME(Redis, getKeys, arginfo_keys, ZEND_ACC_PUBLIC)
PHP_ME(Redis, getLastError, arginfo_void, ZEND_ACC_PUBLIC)
PHP_ME(Redis, getMode, arginfo_void, ZEND_ACC_PUBLIC)
PHP_ME(Redis, getMultiple, arginfo_mget, ZEND_ACC_PUBLIC)
PHP_ME(Redis, getOption, arginfo_getoption, ZEND_ACC_PUBLIC)
PHP_ME(Redis, getPersistentID, arginfo_void, ZEND_ACC_PUBLIC)
PHP_ME(Redis, getPort, arginfo_void, ZEND_ACC_PUBLIC)
PHP_ME(Redis, getRange, arginfo_key_start_end, ZEND_ACC_PUBLIC)
PHP_ME(Redis, getReadTimeout, arginfo_void, ZEND_ACC_PUBLIC)
PHP_ME(Redis, getSet, arginfo_key_value, ZEND_ACC_PUBLIC)
PHP_ME(Redis, getTimeout, arginfo_void, ZEND_ACC_PUBLIC)
PHP_ME(Redis, hDel, arginfo_key_members, ZEND_ACC_PUBLIC)
PHP_ME(Redis, hExists, arginfo_key_member, ZEND_ACC_PUBLIC)
PHP_ME(Redis, hGet, arginfo_key_member, ZEND_ACC_PUBLIC)
PHP_ME(Redis, hGetAll, arginfo_key, ZEND_ACC_PUBLIC)
PHP_ME(Redis, hIncrBy, arginfo_key_member_value, ZEND_ACC_PUBLIC)
PHP_ME(Redis, hIncrByFloat, arginfo_key_member_value, ZEND_ACC_PUBLIC)
PHP_ME(Redis, hKeys, arginfo_key, ZEND_ACC_PUBLIC)
PHP_ME(Redis, hLen, arginfo_key, ZEND_ACC_PUBLIC)
PHP_ME(Redis, hMget, arginfo_hmget, ZEND_ACC_PUBLIC)
PHP_ME(Redis, hMset, arginfo_hmset, ZEND_ACC_PUBLIC)
PHP_ME(Redis, hSet, arginfo_key_member_value, ZEND_ACC_PUBLIC)
PHP_ME(Redis, hSetNx, arginfo_key_member_value, ZEND_ACC_PUBLIC)
PHP_ME(Redis, hStrLen, arginfo_key_member, ZEND_ACC_PUBLIC)
PHP_ME(Redis, hVals, arginfo_key, ZEND_ACC_PUBLIC)
PHP_ME(Redis, hscan, arginfo_kscan, ZEND_ACC_PUBLIC)
PHP_ME(Redis, incr, arginfo_key, ZEND_ACC_PUBLIC)
PHP_ME(Redis, incrBy, arginfo_key_value, ZEND_ACC_PUBLIC)
PHP_ME(Redis, incrByFloat, arginfo_key_value, ZEND_ACC_PUBLIC)
PHP_ME(Redis, info, arginfo_info, ZEND_ACC_PUBLIC)
PHP_ME(Redis, isConnected, arginfo_void, ZEND_ACC_PUBLIC)
PHP_ME(Redis, lGet, arginfo_lindex, ZEND_ACC_PUBLIC)
PHP_ME(Redis, lGetRange, arginfo_key_start_end, ZEND_ACC_PUBLIC)
PHP_ME(Redis, lInsert, arginfo_linsert, ZEND_ACC_PUBLIC)
PHP_ME(Redis, lPop, arginfo_key, ZEND_ACC_PUBLIC)
PHP_ME(Redis, lPush, arginfo_key_value, ZEND_ACC_PUBLIC)
PHP_ME(Redis, lPushx, arginfo_key_value, ZEND_ACC_PUBLIC)
PHP_ME(Redis, lRemove, arginfo_lrem, ZEND_ACC_PUBLIC)
PHP_ME(Redis, lSet, arginfo_lset, ZEND_ACC_PUBLIC)
PHP_ME(Redis, lSize, arginfo_key, ZEND_ACC_PUBLIC)
PHP_ME(Redis, lastSave, arginfo_void, ZEND_ACC_PUBLIC)
PHP_ME(Redis, listTrim, arginfo_ltrim, ZEND_ACC_PUBLIC)
PHP_ME(Redis, migrate, arginfo_migrate, ZEND_ACC_PUBLIC)
PHP_ME(Redis, move, arginfo_move, ZEND_ACC_PUBLIC)
PHP_ME(Redis, mset, arginfo_pairs, ZEND_ACC_PUBLIC)
PHP_ME(Redis, msetnx, arginfo_pairs, ZEND_ACC_PUBLIC)
PHP_ME(Redis, multi, arginfo_void, ZEND_ACC_PUBLIC)
PHP_ME(Redis, object, arginfo_object, ZEND_ACC_PUBLIC)
PHP_ME(Redis, pconnect, arginfo_pconnect, ZEND_ACC_PUBLIC)
PHP_ME(Redis, persist, arginfo_key, ZEND_ACC_PUBLIC)
PHP_ME(Redis, pexpire, arginfo_key_timestamp, ZEND_ACC_PUBLIC)
PHP_ME(Redis, pexpireAt, arginfo_key_timestamp, ZEND_ACC_PUBLIC)
PHP_ME(Redis, pfadd, arginfo_pfadd, ZEND_ACC_PUBLIC)
PHP_ME(Redis, pfcount, arginfo_key, ZEND_ACC_PUBLIC)
PHP_ME(Redis, pfmerge, arginfo_pfmerge, ZEND_ACC_PUBLIC)
PHP_ME(Redis, ping, arginfo_void, ZEND_ACC_PUBLIC)
PHP_ME(Redis, pipeline, arginfo_void, ZEND_ACC_PUBLIC)
PHP_ME(Redis, psetex, arginfo_key_expire_value, ZEND_ACC_PUBLIC)
PHP_ME(Redis, psubscribe, arginfo_psubscribe, ZEND_ACC_PUBLIC)
PHP_ME(Redis, pttl, arginfo_key, ZEND_ACC_PUBLIC)
PHP_ME(Redis, publish, arginfo_publish, ZEND_ACC_PUBLIC)
PHP_ME(Redis, pubsub, arginfo_pubsub, ZEND_ACC_PUBLIC)
PHP_ME(Redis, punsubscribe, arginfo_punsubscribe, ZEND_ACC_PUBLIC)
PHP_ME(Redis, rPop, arginfo_key, ZEND_ACC_PUBLIC)
PHP_ME(Redis, rPush, arginfo_key_value, ZEND_ACC_PUBLIC)
PHP_ME(Redis, rPushx, arginfo_key_value, ZEND_ACC_PUBLIC)
PHP_ME(Redis, randomKey, arginfo_void, ZEND_ACC_PUBLIC)
PHP_ME(Redis, rawcommand, arginfo_rawcommand, ZEND_ACC_PUBLIC)
PHP_ME(Redis, renameKey, arginfo_key_newkey, ZEND_ACC_PUBLIC)
PHP_ME(Redis, renameNx, arginfo_key_newkey, ZEND_ACC_PUBLIC)
PHP_ME(Redis, restore, arginfo_restore, ZEND_ACC_PUBLIC)
PHP_ME(Redis, role, arginfo_void, ZEND_ACC_PUBLIC)
PHP_ME(Redis, rpoplpush, arginfo_rpoplpush, ZEND_ACC_PUBLIC)
PHP_ME(Redis, sAdd, arginfo_key_value, ZEND_ACC_PUBLIC)
PHP_ME(Redis, sAddArray, arginfo_sadd_array, ZEND_ACC_PUBLIC)
PHP_ME(Redis, sContains, arginfo_key_value, ZEND_ACC_PUBLIC)
PHP_ME(Redis, sDiff, arginfo_nkeys, ZEND_ACC_PUBLIC)
PHP_ME(Redis, sDiffStore, arginfo_dst_nkeys, ZEND_ACC_PUBLIC)
PHP_ME(Redis, sInter, arginfo_nkeys, ZEND_ACC_PUBLIC)
PHP_ME(Redis, sInterStore, arginfo_dst_nkeys, ZEND_ACC_PUBLIC)
PHP_ME(Redis, sMembers, arginfo_key, ZEND_ACC_PUBLIC)
PHP_ME(Redis, sMove, arginfo_smove, ZEND_ACC_PUBLIC)
PHP_ME(Redis, sPop, arginfo_key, ZEND_ACC_PUBLIC)
PHP_ME(Redis, sRandMember, arginfo_srand_member, ZEND_ACC_PUBLIC)
PHP_ME(Redis, sRemove, arginfo_key_value, ZEND_ACC_PUBLIC)
PHP_ME(Redis, sSize, arginfo_key, ZEND_ACC_PUBLIC)
PHP_ME(Redis, sUnion, arginfo_nkeys, ZEND_ACC_PUBLIC)
PHP_ME(Redis, sUnionStore, arginfo_dst_nkeys, ZEND_ACC_PUBLIC)
PHP_ME(Redis, save, arginfo_void, ZEND_ACC_PUBLIC)
PHP_ME(Redis, scan, arginfo_scan, ZEND_ACC_PUBLIC)
PHP_ME(Redis, script, arginfo_script, ZEND_ACC_PUBLIC)
PHP_ME(Redis, select, arginfo_select, ZEND_ACC_PUBLIC)
PHP_ME(Redis, set, arginfo_set, ZEND_ACC_PUBLIC)
PHP_ME(Redis, setBit, arginfo_key_offset_value, ZEND_ACC_PUBLIC)
PHP_ME(Redis, setOption, arginfo_setoption, ZEND_ACC_PUBLIC)
PHP_ME(Redis, setRange, arginfo_key_offset_value, ZEND_ACC_PUBLIC)
PHP_ME(Redis, setTimeout, arginfo_expire, ZEND_ACC_PUBLIC)
PHP_ME(Redis, setex, arginfo_key_expire_value, ZEND_ACC_PUBLIC)
PHP_ME(Redis, setnx, arginfo_key_value, ZEND_ACC_PUBLIC)
PHP_ME(Redis, slaveof, arginfo_slaveof, ZEND_ACC_PUBLIC)
PHP_ME(Redis, slowlog, arginfo_slowlog, ZEND_ACC_PUBLIC)
PHP_ME(Redis, sort, arginfo_sort, ZEND_ACC_PUBLIC)
PHP_ME(Redis, sortAsc, arginfo_generic_sort, ZEND_ACC_PUBLIC)
PHP_ME(Redis, sortAscAlpha, arginfo_generic_sort, ZEND_ACC_PUBLIC)
PHP_ME(Redis, sortDesc, arginfo_generic_sort, ZEND_ACC_PUBLIC)
PHP_ME(Redis, sortDescAlpha, arginfo_generic_sort, ZEND_ACC_PUBLIC)
PHP_ME(Redis, sscan, arginfo_kscan, ZEND_ACC_PUBLIC)
PHP_ME(Redis, strlen, arginfo_key, ZEND_ACC_PUBLIC)
PHP_ME(Redis, subscribe, arginfo_subscribe, ZEND_ACC_PUBLIC)
PHP_ME(Redis, swapdb, arginfo_swapdb, ZEND_ACC_PUBLIC)
PHP_ME(Redis, time, arginfo_void, ZEND_ACC_PUBLIC)
PHP_ME(Redis, ttl, arginfo_key, ZEND_ACC_PUBLIC)
PHP_ME(Redis, type, arginfo_key, ZEND_ACC_PUBLIC)
PHP_ME(Redis, unlink, arginfo_nkeys, ZEND_ACC_PUBLIC)
PHP_ME(Redis, unsubscribe, arginfo_unsubscribe, ZEND_ACC_PUBLIC)
PHP_ME(Redis, unwatch, arginfo_void, ZEND_ACC_PUBLIC)
PHP_ME(Redis, wait, arginfo_wait, ZEND_ACC_PUBLIC)
PHP_ME(Redis, watch, arginfo_watch, ZEND_ACC_PUBLIC)
PHP_ME(Redis, zAdd, arginfo_zadd, ZEND_ACC_PUBLIC)
PHP_ME(Redis, zCard, arginfo_key, ZEND_ACC_PUBLIC)
PHP_ME(Redis, zCount, arginfo_key_min_max, ZEND_ACC_PUBLIC)
PHP_ME(Redis, zDelete, arginfo_key_members, ZEND_ACC_PUBLIC)
PHP_ME(Redis, zDeleteRangeByRank, arginfo_key_start_end, ZEND_ACC_PUBLIC)
PHP_ME(Redis, zDeleteRangeByScore, arginfo_key_min_max, ZEND_ACC_PUBLIC)
PHP_ME(Redis, zIncrBy, arginfo_zincrby, ZEND_ACC_PUBLIC)
PHP_ME(Redis, zInter, arginfo_zstore, ZEND_ACC_PUBLIC)
PHP_ME(Redis, zLexCount, arginfo_key_min_max, ZEND_ACC_PUBLIC)
PHP_ME(Redis, zRange, arginfo_zrange, ZEND_ACC_PUBLIC)
PHP_ME(Redis, zRangeByLex, arginfo_zrangebylex, ZEND_ACC_PUBLIC)
PHP_ME(Redis, zRangeByScore, arginfo_zrangebyscore, ZEND_ACC_PUBLIC)
PHP_ME(Redis, zRank, arginfo_key_member, ZEND_ACC_PUBLIC)
PHP_ME(Redis, zRemRangeByLex, arginfo_key_min_max, ZEND_ACC_PUBLIC)
PHP_ME(Redis, zRevRange, arginfo_zrange, ZEND_ACC_PUBLIC)
PHP_ME(Redis, zRevRangeByLex, arginfo_zrangebylex, ZEND_ACC_PUBLIC)
PHP_ME(Redis, zRevRangeByScore, arginfo_zrangebyscore, ZEND_ACC_PUBLIC)
PHP_ME(Redis, zRevRank, arginfo_key_member, ZEND_ACC_PUBLIC)
PHP_ME(Redis, zScore, arginfo_key_member, ZEND_ACC_PUBLIC)
PHP_ME(Redis, zUnion, arginfo_zstore, ZEND_ACC_PUBLIC)
PHP_ME(Redis, zscan, arginfo_kscan, ZEND_ACC_PUBLIC)
PHP_MALIAS(Redis, del, delete, arginfo_del, ZEND_ACC_PUBLIC)
PHP_MALIAS(Redis, evaluate, eval, arginfo_eval, ZEND_ACC_PUBLIC)
PHP_MALIAS(Redis, evaluateSha, evalsha, arginfo_evalsha, ZEND_ACC_PUBLIC)
PHP_MALIAS(Redis, expire, setTimeout, arginfo_expire, ZEND_ACC_PUBLIC)
PHP_MALIAS(Redis, keys, getKeys, arginfo_keys, ZEND_ACC_PUBLIC)
PHP_MALIAS(Redis, lLen, lSize, arginfo_key, ZEND_ACC_PUBLIC)
PHP_MALIAS(Redis, lindex, lGet, arginfo_lindex, ZEND_ACC_PUBLIC)
PHP_MALIAS(Redis, lrange, lGetRange, arginfo_key_start_end, ZEND_ACC_PUBLIC)
PHP_MALIAS(Redis, lrem, lRemove, arginfo_lrem, ZEND_ACC_PUBLIC)
PHP_MALIAS(Redis, ltrim, listTrim, arginfo_ltrim, ZEND_ACC_PUBLIC)
PHP_MALIAS(Redis, mget, getMultiple, arginfo_mget, ZEND_ACC_PUBLIC)
PHP_MALIAS(Redis, open, connect, arginfo_connect, ZEND_ACC_PUBLIC)
PHP_MALIAS(Redis, popen, pconnect, arginfo_pconnect, ZEND_ACC_PUBLIC)
PHP_MALIAS(Redis, rename, renameKey, arginfo_key_newkey, ZEND_ACC_PUBLIC)
PHP_MALIAS(Redis, sGetMembers, sMembers, arginfo_key, ZEND_ACC_PUBLIC)
PHP_MALIAS(Redis, scard, sSize, arginfo_key, ZEND_ACC_PUBLIC)
PHP_MALIAS(Redis, sendEcho, echo, arginfo_echo, ZEND_ACC_PUBLIC)
PHP_MALIAS(Redis, sismember, sContains, arginfo_key_value, ZEND_ACC_PUBLIC)
PHP_MALIAS(Redis, srem, sRemove, arginfo_key_value, ZEND_ACC_PUBLIC)
PHP_MALIAS(Redis, substr, getRange, arginfo_key_start_end, ZEND_ACC_PUBLIC)
PHP_MALIAS(Redis, zRem, zDelete, arginfo_key_members, ZEND_ACC_PUBLIC)
PHP_MALIAS(Redis, zRemRangeByRank, zDeleteRangeByRank, arginfo_key_min_max, ZEND_ACC_PUBLIC)
PHP_MALIAS(Redis, zRemRangeByScore, zDeleteRangeByScore, arginfo_key_min_max, ZEND_ACC_PUBLIC)
PHP_MALIAS(Redis, zRemove, zDelete, arginfo_key_members, ZEND_ACC_PUBLIC)
PHP_MALIAS(Redis, zRemoveRangeByScore, zDeleteRangeByScore, arginfo_key_min_max, ZEND_ACC_PUBLIC)
PHP_MALIAS(Redis, zReverseRange, zRevRange, arginfo_zrange, ZEND_ACC_PUBLIC)
PHP_MALIAS(Redis, zSize, zCard, arginfo_key, ZEND_ACC_PUBLIC)
PHP_MALIAS(Redis, zinterstore, zInter, arginfo_zstore, ZEND_ACC_PUBLIC)
PHP_MALIAS(Redis, zunionstore, zUnion, arginfo_zstore, ZEND_ACC_PUBLIC)
PHP_FE_END
};
static const zend_module_dep redis_deps[] = {
#ifdef HAVE_REDIS_IGBINARY
ZEND_MOD_REQUIRED("igbinary")
#endif
ZEND_MOD_END
};
zend_module_entry redis_module_entry = {
#if ZEND_MODULE_API_NO >= 20010901
STANDARD_MODULE_HEADER_EX,
NULL,
redis_deps,
#endif
"redis",
NULL,
PHP_MINIT(redis),
PHP_MSHUTDOWN(redis),
NULL,
NULL,
PHP_MINFO(redis),
#if ZEND_MODULE_API_NO >= 20010901
PHP_REDIS_VERSION,
#endif
STANDARD_MODULE_PROPERTIES
};
#ifdef COMPILE_DL_REDIS
ZEND_GET_MODULE(redis)
#endif
/* Send a static DISCARD in case we're in MULTI mode. */
static int
redis_send_discard(RedisSock *redis_sock TSRMLS_DC)
{
int result = FAILURE;
char *cmd, *resp;
int resp_len, cmd_len;
/* format our discard command */
cmd_len = REDIS_SPPRINTF(&cmd, "DISCARD", "");
/* send our DISCARD command */
if (redis_sock_write(redis_sock, cmd, cmd_len TSRMLS_CC) >= 0 &&
(resp = redis_sock_read(redis_sock,&resp_len TSRMLS_CC)) != NULL)
{
/* success if we get OK */
result = (resp_len == 3 && strncmp(resp,"+OK", 3) == 0) ? SUCCESS:FAILURE;
/* free our response */
efree(resp);
}
/* free our command */
efree(cmd);
/* return success/failure */
return result;
}
static void
free_reply_callbacks(RedisSock *redis_sock)
{
fold_item *fi;
for (fi = redis_sock->head; fi; ) {
fold_item *fi_next = fi->next;
free(fi);
fi = fi_next;
}
redis_sock->head = NULL;
redis_sock->current = NULL;
}
#if (PHP_MAJOR_VERSION < 7)
void
free_redis_object(void *object TSRMLS_DC)
{
redis_object *redis = (redis_object *)object;
zend_object_std_dtor(&redis->std TSRMLS_CC);
if (redis->sock) {
redis_sock_disconnect(redis->sock TSRMLS_CC);
redis_free_socket(redis->sock);
}
efree(redis);
}
zend_object_value
create_redis_object(zend_class_entry *ce TSRMLS_DC)
{
zend_object_value retval;
redis_object *redis = ecalloc(1, sizeof(redis_object));
memset(redis, 0, sizeof(redis_object));
zend_object_std_init(&redis->std, ce TSRMLS_CC);
#if PHP_VERSION_ID < 50399
zval *tmp;
zend_hash_copy(redis->std.properties, &ce->default_properties,
(copy_ctor_func_t)zval_add_ref, (void *)&tmp, sizeof(zval *));
#else
object_properties_init(&redis->std, ce);
#endif
retval.handle = zend_objects_store_put(redis,
(zend_objects_store_dtor_t)zend_objects_destroy_object,
(zend_objects_free_object_storage_t)free_redis_object,
NULL TSRMLS_CC);
retval.handlers = zend_get_std_object_handlers();
return retval;
}
#else
zend_object_handlers redis_object_handlers;
void
free_redis_object(zend_object *object)
{
redis_object *redis = (redis_object *)((char *)(object) - XtOffsetOf(redis_object, std));
zend_object_std_dtor(&redis->std TSRMLS_CC);
if (redis->sock) {
redis_sock_disconnect(redis->sock TSRMLS_CC);
redis_free_socket(redis->sock);
}
}
zend_object *
create_redis_object(zend_class_entry *ce TSRMLS_DC)
{
redis_object *redis = ecalloc(1, sizeof(redis_object) + zend_object_properties_size(ce));
redis->sock = NULL;
zend_object_std_init(&redis->std, ce TSRMLS_CC);
object_properties_init(&redis->std, ce);
memcpy(&redis_object_handlers, zend_get_std_object_handlers(), sizeof(redis_object_handlers));
redis_object_handlers.offset = XtOffsetOf(redis_object, std);
redis_object_handlers.free_obj = free_redis_object;
redis->std.handlers = &redis_object_handlers;
return &redis->std;
}
#endif
static zend_always_inline RedisSock *
redis_sock_get_instance(zval *id TSRMLS_DC, int no_throw)
{
redis_object *redis;
if (Z_TYPE_P(id) == IS_OBJECT) {
redis = PHPREDIS_GET_OBJECT(redis_object, id);
if (redis->sock) {
return redis->sock;
}
}
// Throw an exception unless we've been requested not to
if (!no_throw) {
zend_throw_exception(redis_exception_ce, "Redis server went away", 0 TSRMLS_CC);
}
return NULL;
}
/**
* redis_sock_get
*/
PHP_REDIS_API RedisSock *
redis_sock_get(zval *id TSRMLS_DC, int no_throw)
{
RedisSock *redis_sock;
if ((redis_sock = redis_sock_get_instance(id TSRMLS_CC, no_throw)) == NULL) {
return NULL;
}
if (redis_sock->lazy_connect) {
redis_sock->lazy_connect = 0;
if (redis_sock_server_open(redis_sock TSRMLS_CC) < 0) {
return NULL;
}
}
return redis_sock;
}
/**
* redis_sock_get_direct
* Returns our attached RedisSock pointer if we're connected
*/
PHP_REDIS_API RedisSock *redis_sock_get_connected(INTERNAL_FUNCTION_PARAMETERS) {
zval *object;
RedisSock *redis_sock;
// If we can't grab our object, or get a socket, or we're not connected,
// return NULL
if((zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O",
&object, redis_ce) == FAILURE) ||
(redis_sock = redis_sock_get(object TSRMLS_CC, 1)) == NULL ||
redis_sock->status != REDIS_SOCK_STATUS_CONNECTED)
{
return NULL;
}
/* Return our socket */
return redis_sock;
}
/* Redis and RedisCluster objects share serialization/prefixing settings so
* this is a generic function to add class constants to either */
static void add_class_constants(zend_class_entry *ce, int is_cluster TSRMLS_DC) {
zend_declare_class_constant_long(ce, ZEND_STRL("REDIS_NOT_FOUND"), REDIS_NOT_FOUND TSRMLS_CC);
zend_declare_class_constant_long(ce, ZEND_STRL("REDIS_STRING"), REDIS_STRING TSRMLS_CC);
zend_declare_class_constant_long(ce, ZEND_STRL("REDIS_SET"), REDIS_SET TSRMLS_CC);
zend_declare_class_constant_long(ce, ZEND_STRL("REDIS_LIST"), REDIS_LIST TSRMLS_CC);
zend_declare_class_constant_long(ce, ZEND_STRL("REDIS_ZSET"), REDIS_ZSET TSRMLS_CC);
zend_declare_class_constant_long(ce, ZEND_STRL("REDIS_HASH"), REDIS_HASH TSRMLS_CC);
/* Cluster doesn't support pipelining at this time */
if(!is_cluster) {
zend_declare_class_constant_long(ce, ZEND_STRL("PIPELINE"), PIPELINE TSRMLS_CC);
}
/* Add common mode constants */
zend_declare_class_constant_long(ce, ZEND_STRL("ATOMIC"), ATOMIC TSRMLS_CC);
zend_declare_class_constant_long(ce, ZEND_STRL("MULTI"), MULTI TSRMLS_CC);
/* options */
zend_declare_class_constant_long(ce, ZEND_STRL("OPT_SERIALIZER"), REDIS_OPT_SERIALIZER TSRMLS_CC);
zend_declare_class_constant_long(ce, ZEND_STRL("OPT_PREFIX"), REDIS_OPT_PREFIX TSRMLS_CC);
zend_declare_class_constant_long(ce, ZEND_STRL("OPT_READ_TIMEOUT"), REDIS_OPT_READ_TIMEOUT TSRMLS_CC);
zend_declare_class_constant_long(ce, ZEND_STRL("OPT_TCP_KEEPALIVE"), REDIS_OPT_TCP_KEEPALIVE TSRMLS_CC);
zend_declare_class_constant_long(ce, ZEND_STRL("OPT_COMPRESSION"), REDIS_OPT_COMPRESSION TSRMLS_CC);
/* serializer */
zend_declare_class_constant_long(ce, ZEND_STRL("SERIALIZER_NONE"), REDIS_SERIALIZER_NONE TSRMLS_CC);
zend_declare_class_constant_long(ce, ZEND_STRL("SERIALIZER_PHP"), REDIS_SERIALIZER_PHP TSRMLS_CC);
#ifdef HAVE_REDIS_IGBINARY
zend_declare_class_constant_long(ce, ZEND_STRL("SERIALIZER_IGBINARY"), REDIS_SERIALIZER_IGBINARY TSRMLS_CC);
#endif
/* compression */
zend_declare_class_constant_long(ce, ZEND_STRL("COMPRESSION_NONE"), REDIS_COMPRESSION_NONE TSRMLS_CC);
#ifdef HAVE_REDIS_LZF
zend_declare_class_constant_long(ce, ZEND_STRL("COMPRESSION_LZF"), REDIS_COMPRESSION_LZF TSRMLS_CC);
#endif
/* scan options*/
zend_declare_class_constant_long(ce, ZEND_STRL("OPT_SCAN"), REDIS_OPT_SCAN TSRMLS_CC);
zend_declare_class_constant_long(ce, ZEND_STRL("SCAN_RETRY"), REDIS_SCAN_RETRY TSRMLS_CC);
zend_declare_class_constant_long(ce, ZEND_STRL("SCAN_NORETRY"), REDIS_SCAN_NORETRY TSRMLS_CC);
/* Cluster option to allow for slave failover */
if (is_cluster) {
zend_declare_class_constant_long(ce, ZEND_STRL("OPT_SLAVE_FAILOVER"), REDIS_OPT_FAILOVER TSRMLS_CC);
zend_declare_class_constant_long(ce, ZEND_STRL("FAILOVER_NONE"), REDIS_FAILOVER_NONE TSRMLS_CC);
zend_declare_class_constant_long(ce, ZEND_STRL("FAILOVER_ERROR"), REDIS_FAILOVER_ERROR TSRMLS_CC);
zend_declare_class_constant_long(ce, ZEND_STRL("FAILOVER_DISTRIBUTE"), REDIS_FAILOVER_DISTRIBUTE TSRMLS_CC);
zend_declare_class_constant_long(ce, ZEND_STRL("FAILOVER_DISTRIBUTE_SLAVES"), REDIS_FAILOVER_DISTRIBUTE_SLAVES TSRMLS_CC);
}
zend_declare_class_constant_stringl(ce, "AFTER", 5, "after", 5 TSRMLS_CC);
zend_declare_class_constant_stringl(ce, "BEFORE", 6, "before", 6 TSRMLS_CC);
}
/**
* PHP_MINIT_FUNCTION
*/
PHP_MINIT_FUNCTION(redis)
{
struct timeval tv;
zend_class_entry redis_class_entry;
zend_class_entry redis_array_class_entry;
zend_class_entry redis_cluster_class_entry;
zend_class_entry redis_exception_class_entry;
zend_class_entry redis_cluster_exception_class_entry;
zend_class_entry *exception_ce = NULL;
/* Seed random generator (for RedisCluster failover) */
gettimeofday(&tv, NULL);
srand(tv.tv_usec * tv.tv_sec);
REGISTER_INI_ENTRIES();
/* Redis class */
INIT_CLASS_ENTRY(redis_class_entry, "Redis", redis_functions);
redis_ce = zend_register_internal_class(&redis_class_entry TSRMLS_CC);
redis_ce->create_object = create_redis_object;
/* RedisArray class */
INIT_CLASS_ENTRY(redis_array_class_entry, "RedisArray", redis_array_functions);
redis_array_ce = zend_register_internal_class(&redis_array_class_entry TSRMLS_CC);
redis_array_ce->create_object = create_redis_array_object;
/* RedisCluster class */
INIT_CLASS_ENTRY(redis_cluster_class_entry, "RedisCluster", redis_cluster_functions);
redis_cluster_ce = zend_register_internal_class(&redis_cluster_class_entry TSRMLS_CC);
redis_cluster_ce->create_object = create_cluster_context;
/* Base Exception class */
#if HAVE_SPL
exception_ce = zend_hash_str_find_ptr(CG(class_table), "RuntimeException", sizeof("RuntimeException") - 1);
#endif
if (exception_ce == NULL) {
#if (PHP_MAJOR_VERSION == 5) && (PHP_MINOR_VERSION < 2)
exception_ce = zend_exception_get_default();
#else
exception_ce = zend_exception_get_default(TSRMLS_C);
#endif
}
/* RedisException class */
INIT_CLASS_ENTRY(redis_exception_class_entry, "RedisException", NULL);
redis_exception_ce = zend_register_internal_class_ex(
&redis_exception_class_entry,
#if (PHP_MAJOR_VERSION < 7)
exception_ce, NULL TSRMLS_CC
#else
exception_ce
#endif
);
/* RedisClusterException class */
INIT_CLASS_ENTRY(redis_cluster_exception_class_entry,
"RedisClusterException", NULL);
redis_cluster_exception_ce = zend_register_internal_class_ex(
&redis_cluster_exception_class_entry,
#if (PHP_MAJOR_VERSION < 7)
exception_ce, NULL TSRMLS_CC
#else
exception_ce
#endif
);
/* Add shared class constants to Redis and RedisCluster objects */
add_class_constants(redis_ce, 0 TSRMLS_CC);
add_class_constants(redis_cluster_ce, 1 TSRMLS_CC);
#ifdef PHP_SESSION
php_session_register_module(&ps_mod_redis);
php_session_register_module(&ps_mod_redis_cluster);
#endif
return SUCCESS;
}
/**
* PHP_MSHUTDOWN_FUNCTION
*/
PHP_MSHUTDOWN_FUNCTION(redis)
{
return SUCCESS;
}
/**
* PHP_MINFO_FUNCTION
*/
PHP_MINFO_FUNCTION(redis)
{
php_info_print_table_start();
php_info_print_table_header(2, "Redis Support", "enabled");
php_info_print_table_row(2, "Redis Version", PHP_REDIS_VERSION);
#ifdef GIT_REVISION
php_info_print_table_row(2, "Git revision", "$Id: " GIT_REVISION " $");
#endif
#ifdef HAVE_REDIS_IGBINARY
php_info_print_table_row(2, "Available serializers", "php, igbinary");
#else
php_info_print_table_row(2, "Available serializers", "php");
#endif
#ifdef HAVE_REDIS_LZF
php_info_print_table_row(2, "Available compression", "lzf");
#endif
php_info_print_table_end();
}
/* {{{ proto Redis Redis::__construct()
Public constructor */
PHP_METHOD(Redis, __construct)
{
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "") == FAILURE) {
RETURN_FALSE;
}
}
/* }}} */
/* {{{ proto Redis Redis::__destruct()
Public Destructor
*/
PHP_METHOD(Redis,__destruct) {
if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "") == FAILURE) {
RETURN_FALSE;
}
// Grab our socket
RedisSock *redis_sock;
if ((redis_sock = redis_sock_get_instance(getThis() TSRMLS_CC, 1)) == NULL) {
RETURN_FALSE;
}
// If we think we're in MULTI mode, send a discard
if (IS_MULTI(redis_sock)) {
if (!IS_PIPELINE(redis_sock) && redis_sock->stream) {
// Discard any multi commands, and free any callbacks that have been
// queued
redis_send_discard(redis_sock TSRMLS_CC);
}
free_reply_callbacks(redis_sock);
}
}
/* {{{ proto boolean Redis::connect(string host, int port [, double timeout [, long retry_interval]])
*/
PHP_METHOD(Redis, connect)
{
if (redis_connect(INTERNAL_FUNCTION_PARAM_PASSTHRU, 0) == FAILURE) {
RETURN_FALSE;
} else {
RETURN_TRUE;
}
}
/* }}} */
/* {{{ proto boolean Redis::pconnect(string host, int port [, double timeout])
*/
PHP_METHOD(Redis, pconnect)
{
if (redis_connect(INTERNAL_FUNCTION_PARAM_PASSTHRU, 1) == FAILURE) {
RETURN_FALSE;
} else {
RETURN_TRUE;
}
}
/* }}} */
PHP_REDIS_API int
redis_connect(INTERNAL_FUNCTION_PARAMETERS, int persistent)
{
zval *object;
char *host = NULL, *persistent_id = "";
zend_long port = -1, retry_interval = 0;
strlen_t host_len, persistent_id_len;
double timeout = 0.0, read_timeout = 0.0;
redis_object *redis;
#ifdef ZTS
/* not sure how in threaded mode this works so disabled persistence at
* first */
persistent = 0;
#endif
if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(),
"Os|ldsld", &object, redis_ce, &host,
&host_len, &port, &timeout, &persistent_id,
&persistent_id_len, &retry_interval,
&read_timeout) == FAILURE)
{
return FAILURE;
} else if (!persistent) {
persistent_id = NULL;
}
if (timeout < 0L || timeout > INT_MAX) {
zend_throw_exception(redis_exception_ce,
"Invalid connect timeout", 0 TSRMLS_CC);
return FAILURE;
}
if (read_timeout < 0L || read_timeout > INT_MAX) {
zend_throw_exception(redis_exception_ce,
"Invalid read timeout", 0 TSRMLS_CC);
return FAILURE;
}
if (retry_interval < 0L || retry_interval > INT_MAX) {
zend_throw_exception(redis_exception_ce, "Invalid retry interval",
0 TSRMLS_CC);
return FAILURE;
}
/* If it's not a unix socket, set to default */
if(port == -1 && host_len && host[0] != '/') {
port = 6379;
}
redis = PHPREDIS_GET_OBJECT(redis_object, object);
/* if there is a redis sock already we have to remove it */
if (redis->sock) {
redis_sock_disconnect(redis->sock TSRMLS_CC);
redis_free_socket(redis->sock);
}
redis->sock = redis_sock_create(host, host_len, port, timeout, read_timeout, persistent,
persistent_id, retry_interval, 0);
if (redis_sock_server_open(redis->sock TSRMLS_CC) < 0) {
if (redis->sock->err) {
zend_throw_exception(redis_exception_ce, ZSTR_VAL(redis->sock->err), 0 TSRMLS_CC);
}
redis_free_socket(redis->sock);
redis->sock = NULL;
return FAILURE;
}
return SUCCESS;
}
/* {{{ proto long Redis::bitop(string op, string key, ...) */
PHP_METHOD(Redis, bitop)
{
REDIS_PROCESS_CMD(bitop, redis_long_response);
}
/* }}} */
/* {{{ proto long Redis::bitcount(string key, [int start], [int end])
*/
PHP_METHOD(Redis, bitcount)
{
REDIS_PROCESS_CMD(bitcount, redis_long_response);
}
/* }}} */
/* {{{ proto integer Redis::bitpos(string key, int bit, [int start, int end]) */
PHP_METHOD(Redis, bitpos)
{
REDIS_PROCESS_CMD(bitpos, redis_long_response);
}
/* }}} */
/* {{{ proto boolean Redis::close()
*/
PHP_METHOD(Redis, close)
{
RedisSock *redis_sock = redis_sock_get_connected(INTERNAL_FUNCTION_PARAM_PASSTHRU);
if (redis_sock && redis_sock_disconnect(redis_sock TSRMLS_CC)) {
RETURN_TRUE;
}
RETURN_FALSE;
}