forked from e-oz/Memory
-
Notifications
You must be signed in to change notification settings - Fork 0
/
RedisServer.php
1236 lines (1082 loc) · 28.7 KB
/
RedisServer.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
namespace Jamm\Memory;
/**
* RedisServer allows you to work with Redis storage in PHP
* Redis version compatibility: 2.6.9 (and below)
* You can send custom command using send_command() method.
*/
class RedisServer implements IRedisServer
{
protected $connection;
private $host = 'localhost';
private $port = 6379;
private $repeat_reconnected = false;
public function __construct($host = 'localhost', $port = '6379')
{
$this->host = $host;
$this->port = $port;
}
public function connect($host, $port)
{
if (!empty($this->connection))
{
fclose($this->connection);
$this->connection = NULL;
}
$socket = fsockopen($host, $port, $errno, $errstr);
if (!$socket)
{
$this->reportError('Connection error: '.$errno.':'.$errstr);
return false;
}
$this->connection = $socket;
return $socket;
}
protected function reportError($msg)
{
trigger_error($msg, E_USER_WARNING);
}
/**
* Execute send_command and return the result
* Each entity of the send_command should be passed as argument
* Example:
* send_command('set','key','example value');
* or:
* send_command('multi');
* send_command('config','ResetStat'); // if command contain 2 words, they should be separated
* send_command('set','a', serialize($arr));
* send_command('set','b', 1);
* send_command('execute');
* @return array|bool|int|null|string
*/
public function send_command()
{
return $this->_send(func_get_args());
}
protected function _send($args)
{
if (empty($this->connection))
{
if (!$this->connect($this->host, $this->port))
{
return false;
}
}
$command = '*'.count($args)."\r\n";
foreach ($args as $arg) $command .= "$".strlen($arg)."\r\n".$arg."\r\n";
$w = fwrite($this->connection, $command);
if (!$w)
{
//if connection was lost
$this->connect($this->host, $this->port);
if (!fwrite($this->connection, $command))
{
$this->reportError('command was not sent');
return false;
}
}
$answer = $this->_read_reply();
if ($answer===false && $this->repeat_reconnected)
{
if (fwrite($this->connection, $command))
{
$answer = $this->_read_reply();
}
$this->repeat_reconnected = false;
}
return $answer;
}
/* If some command is not wrapped... */
public function __call($name, $args)
{
$command = trim(str_replace('_', ' ', $name, $replaced));
if ($replaced > 0)
{
$commands = explode(' ', $command);
$args = array_merge($commands, $args);
}
else
{
array_unshift($args, $command);
}
return $this->_send($args);
}
protected function _read_reply()
{
$server_reply = fgets($this->connection);
if ($server_reply===false)
{
if (!$this->connect($this->host, $this->port))
{
return false;
}
else
{
$server_reply = fgets($this->connection);
if (empty($server_reply))
{
$this->repeat_reconnected = true;
return false;
}
}
}
$reply = trim($server_reply);
$response = null;
/**
* Thanks to Justin Poliey for original code of parsing the answer
* https://github.com/jdp
* Error was fixed there: https://github.com/jamm/redisent
*/
switch ($reply[0])
{
/* Error reply */
case '-':
$this->reportError('error: '.$reply);
return false;
/* Inline reply */
case '+':
return substr($reply, 1);
/* Bulk reply */
case '$':
if ($reply=='$-1') return null;
$response = null;
$size = intval(substr($reply, 1));
if ($size > 0)
{
$response = stream_get_contents($this->connection, $size);
}
fread($this->connection, 2); /* discard crlf */
break;
/* Multi-bulk reply */
case '*':
$count = substr($reply, 1);
if ($count=='-1') return null;
$response = array();
for ($i = 0; $i < $count; $i++)
{
$response[] = $this->_read_reply();
}
break;
/* Integer reply */
case ':':
return intval(substr($reply, 1));
break;
default:
$this->reportError('Non-protocol answer: '.print_r($server_reply, 1));
return false;
}
return $response;
}
public function Get($key)
{
return $this->_send(array('get', $key));
}
public function Set($key, $value)
{
return $this->_send(array('set', $key, $value));
}
public function SetEx($key, $seconds, $value)
{
return $this->_send(array('setex', $key, $seconds, $value));
}
public function Keys($pattern)
{
return $this->_send(array('keys', $pattern));
}
public function Multi()
{
return $this->_send(array('multi'));
}
public function sAdd($key, $member)
{
if (!is_array($member)) $member = func_get_args();
else array_unshift($member, $key);
return $this->__call('sadd', $member);
}
public function sMembers($key)
{
return $this->_send(array('smembers', $key));
}
public function hSet($key, $field, $value)
{
return $this->_send(array('hset', $key, $field, $value));
}
public function hGetAll($key)
{
$arr = $this->_send(array('hgetall', $key));
$c = count($arr);
$r = array();
for ($i = 0; $i < $c; $i += 2)
{
$r[$arr[$i]] = $arr[$i+1];
}
return $r;
}
public function FlushDB()
{
return $this->_send(array('flushdb'));
}
public function Info()
{
return $this->_send(array('info'));
}
/** Close connection */
public function __destruct()
{
if (!empty($this->connection)) fclose($this->connection);
}
public function SetNX($key, $value)
{
return $this->_send(array('setnx', $key, $value));
}
public function Watch($key)
{
$args = func_get_args();
array_unshift($args, 'watch');
return $this->_send($args);
}
public function Exec()
{
return $this->_send(array('exec'));
}
public function Discard()
{
return $this->_send(array('discard'));
}
public function sIsMember($key, $member)
{
return $this->_send(array('sismember', $key, $member));
}
public function sRem($key, $member)
{
if (!is_array($member)) $member = func_get_args();
else array_unshift($member, $key);
return $this->__call('srem', $member);
}
public function Expire($key, $seconds)
{
return $this->_send(array('expire', $key, $seconds));
}
public function TTL($key)
{
return $this->_send(array('ttl', $key));
}
public function Del($key)
{
if (!is_array($key)) $key = func_get_args();
return $this->__call('del', $key);
}
public function IncrBy($key, $increment)
{
return $this->_send(array('incrby', $key, $increment));
}
public function Append($key, $value)
{
return $this->_send(array('append', $key, $value));
}
public function Auth($password)
{
return $this->_send(array('Auth', $password));
}
public function bgRewriteAOF()
{
return $this->_send(array('bgRewriteAOF'));
}
public function bgSave()
{
return $this->_send(array('bgSave'));
}
public function BLPop($key, $timeout)
{
if (!is_array($key)) $key = func_get_args();
else array_push($key, $timeout);
return $this->__call('BLPop', $key);
}
public function BRPop($key, $timeout)
{
if (!is_array($key)) $key = func_get_args();
else array_push($key, $timeout);
return $this->__call('BRPop', $key);
}
public function BRPopLPush($source, $destination, $timeout)
{
return $this->_send(array('BRPopLPush', $source, $destination, $timeout));
}
public function Config_Get($parameter)
{
return $this->_send(array('CONFIG', 'GET', $parameter));
}
public function Config_Set($parameter, $value)
{
return $this->_send(array('CONFIG', 'SET', $parameter, $value));
}
public function Config_ResetStat()
{
return $this->__call('CONFIG_RESETSTAT', array());
}
public function DBsize()
{
return $this->_send(array('dbsize'));
}
public function Decr($key)
{
return $this->_send(array('decr', $key));
}
public function DecrBy($key, $decrement)
{
return $this->_send(array('DecrBy', $key, $decrement));
}
public function Exists($key)
{
return $this->_send(array('Exists', $key));
}
public function Expireat($key, $timestamp)
{
return $this->_send(array('Expireat', $key, $timestamp));
}
public function FlushAll()
{
return $this->_send(array('flushall'));
}
public function GetBit($key, $offset)
{
return $this->_send(array('GetBit', $key, $offset));
}
public function GetRange($key, $start, $end)
{
return $this->_send(array('getrange', $key, $start, $end));
}
public function GetSet($key, $value)
{
return $this->_send(array('GetSet', $key, $value));
}
public function hDel($key, $field)
{
if (!is_array($field)) $field = func_get_args();
else array_unshift($field, $key);
return $this->__call('hdel', $field);
}
public function hExists($key, $field)
{
return $this->_send(array('hExists', $key, $field));
}
public function hGet($key, $field)
{
return $this->_send(array('hGet', $key, $field));
}
public function hIncrBy($key, $field, $increment)
{
return $this->_send(array('hIncrBy', $key, $field, $increment));
}
public function hKeys($key)
{
return $this->_send(array('hKeys', $key));
}
public function hLen($key)
{
return $this->_send(array('hLen', $key));
}
public function hMGet($key, array $fields)
{
array_unshift($fields, $key);
return $this->__call('hMGet', $fields);
}
public function hMSet($key, $fields)
{
$args[] = $key;
foreach ($fields as $field => $value)
{
$args[] = $field;
$args[] = $value;
}
return $this->__call('hMSet', $args);
}
public function hSetNX($key, $field, $value)
{
return $this->_send(array('hSetNX', $key, $field, $value));
}
public function hVals($key)
{
return $this->_send(array('hVals', $key));
}
public function Incr($key)
{
return $this->_send(array('Incr', $key));
}
public function LIndex($key, $index)
{
return $this->_send(array('LIndex', $key, $index));
}
public function LInsert($key, $after = true, $pivot, $value)
{
if ($after) $position = self::Position_AFTER;
else $position = self::Position_BEFORE;
return $this->_send(array('LInsert', $key, $position, $pivot, $value));
}
public function LLen($key)
{
return $this->_send(array('LLen', $key));
}
public function LPop($key)
{
return $this->_send(array('LPop', $key));
}
public function LPush($key, $value)
{
if (!is_array($value)) $value = func_get_args();
else array_unshift($value, $key);
return $this->__call('lpush', $value);
}
public function LPushX($key, $value)
{
return $this->_send(array('LPushX', $key, $value));
}
public function LRange($key, $start, $stop)
{
return $this->_send(array('LRange', $key, $start, $stop));
}
public function LRem($key, $count, $value)
{
return $this->_send(array('LRem', $key, $count, $value));
}
public function LSet($key, $index, $value)
{
return $this->_send(array('LSet', $key, $index, $value));
}
public function LTrim($key, $start, $stop)
{
return $this->_send(array('LTrim', $key, $start, $stop));
}
public function MGet($key)
{
if (!is_array($key)) $key = func_get_args();
return $this->__call('MGet', $key);
}
public function Move($key, $db)
{
return $this->_send(array('Move', $key, $db));
}
public function MSet(array $keys)
{
$q = array();
foreach ($keys as $k => $v)
{
$q[] = $k;
$q[] = $v;
}
return $this->__call('MSet', $q);
}
public function MSetNX(array $keys)
{
$q = array();
foreach ($keys as $k => $v)
{
$q[] = $k;
$q[] = $v;
}
return $this->__call('MSetNX', $q);
}
public function Persist($key)
{
return $this->_send(array('Persist', $key));
}
public function PSubscribe($pattern)
{
return $this->_send(array('PSubscribe', $pattern));
}
public function Publish($channel, $message)
{
return $this->_send(array('Publish', $channel, $message));
}
public function PUnsubscribe($pattern = null)
{
if (!empty($pattern))
{
if (!is_array($pattern)) $pattern = array($pattern);
return $this->__call('PUnsubscribe', $pattern);
}
else return $this->_send(array('PUnsubscribe'));
}
public function Quit()
{
return $this->_send(array('Quit'));
}
public function Rename($key, $newkey)
{
return $this->_send(array('Rename', $key, $newkey));
}
public function RenameNX($key, $newkey)
{
return $this->_send(array('RenameNX', $key, $newkey));
}
public function RPop($key)
{
return $this->_send(array('RPop', $key));
}
public function RPopLPush($source, $destination)
{
return $this->_send(array('RPopLPush', $source, $destination));
}
public function RPush($key, $value)
{
if (!is_array($value)) $value = func_get_args();
else array_unshift($value, $key);
return $this->__call('rpush', $value);
}
public function RPushX($key, $value)
{
return $this->_send(array('RPushX', $key, $value));
}
public function sCard($key)
{
return $this->_send(array('sCard', $key));
}
public function sDiff($key)
{
if (!is_array($key)) $key = func_get_args();
return $this->__call('sDiff', $key);
}
public function sDiffStore($destination, $key)
{
if (!is_array($key)) $key = func_get_args();
else array_unshift($key, $destination);
return $this->__call('sDiffStore', $key);
}
public function Select($index)
{
return $this->_send(array('Select', $index));
}
public function SetBit($key, $offset, $value)
{
return $this->_send(array('SetBit', $key, $offset, $value));
}
public function SetRange($key, $offset, $value)
{
return $this->_send(array('SetRange', $key, $offset, $value));
}
public function sInter($key)
{
if (!is_array($key)) $key = func_get_args();
return $this->__call('sInter', $key);
}
public function sInterStore($destination, $key)
{
if (is_array($key)) array_unshift($key, $destination);
else $key = func_get_args();
return $this->__call('sInterStore', $key);
}
public function SlaveOf($host, $port)
{
return $this->_send(array('SlaveOf', $host, $port));
}
public function sMove($source, $destination, $member)
{
return $this->_send(array('sMove', $source, $destination, $member));
}
public function Sort($key, $sort_rule)
{
return $this->_send(array('Sort', $key, $sort_rule));
}
public function StrLen($key)
{
return $this->_send(array('StrLen', $key));
}
public function Subscribe($channel)
{
if (!is_array($channel)) $channel = func_get_args();
return $this->__call('Subscribe', $channel);
}
public function sUnion($key)
{
if (!is_array($key)) $key = func_get_args();
return $this->__call('sUnion', $key);
}
public function sUnionStore($destination, $key)
{
if (!is_array($key)) $key = func_get_args();
else array_unshift($key, $destination);
return $this->__call('sUnionStore', $key);
}
public function Type($key)
{
return $this->_send(array('Type', $key));
}
public function Unsubscribe($channel = '')
{
$args = func_get_args();
if (empty($args)) return $this->_send(array('Unsubscribe'));
else
{
if (is_array($channel)) return $this->__call('Unsubscribe', $channel);
else return $this->__call('Unsubscribe', $args);
}
}
public function Unwatch()
{
return $this->_send(array('Unwatch'));
}
public function zAdd($key, $score, $member = NULL)
{
if (!is_array($score)) $values = func_get_args();
else
{
foreach ($score as $score_value => $member)
{
$values[] = $score_value;
$values[] = $member;
}
array_unshift($values, $key);
}
return $this->__call('zadd', $values);
}
public function zCard($key)
{
return $this->_send(array('zCard', $key));
}
public function zCount($key, $min, $max)
{
return $this->_send(array('zCount', $key, $min, $max));
}
public function zIncrBy($key, $increment, $member)
{
return $this->_send(array('zIncrBy', $key, $increment, $member));
}
public function zInterStore($destination, array $keys, array $weights = null, $aggregate = null)
{
$destination = array($destination, count($keys));
$destination = array_merge($destination, $keys);
if (!empty($weights))
{
$destination[] = 'WEIGHTS';
$destination = array_merge($destination, $weights);
}
if (!empty($aggregate))
{
$destination[] = 'AGGREGATE';
$destination[] = $aggregate;
}
return $this->__call('zInterStore', $destination);
}
public function zRange($key, $start, $stop, $withscores = false)
{
if ($withscores) return $this->_send(array('zRange', $key, $start, $stop, self::WITHSCORES));
else return $this->_send(array('zRange', $key, $start, $stop));
}
public function zRangeByScore($key, $min, $max, $withscores = false, array $limit = null)
{
$args = array($key, $min, $max);
if ($withscores) $args[] = self::WITHSCORES;
if (!empty($limit))
{
$args[] = 'LIMIT';
$args[] = $limit[0];
$args[] = $limit[1];
}
return $this->__call('zRangeByScore', $args);
}
public function zRank($key, $member)
{
return $this->_send(array('zRank', $key, $member));
}
public function zRem($key, $member)
{
if (!is_array($member)) $member = func_get_args();
else array_unshift($member, $key);
return $this->__call('zrem', $member);
}
public function zRemRangeByRank($key, $start, $stop)
{
return $this->_send(array('zRemRangeByRank', $key, $start, $stop));
}
public function zRemRangeByScore($key, $min, $max)
{
return $this->_send(array('zRemRangeByScore', $key, $min, $max));
}
public function zRevRange($key, $start, $stop, $withscores = false)
{
if ($withscores) return $this->_send(array('zRevRange', $key, $start, $stop, self::WITHSCORES));
else return $this->_send(array('zRevRange', $key, $start, $stop));
}
public function zRevRangeByScore($key, $max, $min, $withscores = false, array $limit = null)
{
$args = array($key, $max, $min);
if ($withscores) $args[] = self::WITHSCORES;
if (!empty($limit))
{
$args[] = 'LIMIT';
$args[] = $limit[0];
$args[] = $limit[1];
}
return $this->__call('zRevRangeByScore', $args);
}
public function zRevRank($key, $member)
{
return $this->_send(array('zRevRank', $key, $member));
}
public function zScore($key, $member)
{
return $this->_send(array('zScore', $key, $member));
}
public function zUnionStore($destination, array $keys, array $weights = null, $aggregate = null)
{
$destination = array($destination, count($keys));
$destination = array_merge($destination, $keys);
if (!empty($weights))
{
$destination[] = 'WEIGHTS';
$destination = array_merge($destination, $weights);
}
if (!empty($aggregate))
{
$destination[] = 'AGGREGATE';
$destination[] = $aggregate;
}
return $this->__call('zUnionStore', $destination);
}
/** Internal command used for replication */
public function SYNC()
{
return $this->_send(array('SYNC'));
}
/**
* Get a random member from a set
* @param string $key
* @param int $count
* @return string
*/
public function SRANDMEMBER($key, $count = 1)
{
return $this->_send(array('SRANDMEMBER', $key, $count));
}
/**
* Remove and return a random member from a set
* @param string $key
* @return string
*/
public function SPOP($key)
{
return $this->_send(array('SPOP', $key));
}
/**
* Manages the Redis slow queries log
* @param string $subcommand
* @param string $argument
* @return mixed
*/
public function SLOWLOG($subcommand, $argument = '')
{
return $this->_send(array('SLOWLOG', $subcommand, $argument));
}
/**
* Synchronously save the dataset to disk and then shut down the server
* One of modifiers can be turned on:
* @param boolean $save will force a DB saving operation even if no save points are configured.
* @param boolean $nosave will prevent a DB saving operation even if one or more save points are configured.
* @return bool
*/
public function SHUTDOWN($save = false, $nosave = false)
{
if ($save)
{
return $this->_send(array('SHUTDOWN', 'SAVE'));
}
elseif ($nosave)
{
return $this->_send(array('SHUTDOWN', 'NOSAVE'));
}
return $this->_send(array('SHUTDOWN'));
}
/** Synchronously save the dataset to disk */
public function SAVE()
{
return $this->_send(array('SAVE'));
}
/** Return a random key from the keyspace */
public function RANDOMKEY()
{
return $this->_send(array('RANDOMKEY'));
}
/**
* Inspect the internals of Redis objects
* @param string $subcommand
* @param array $arguments
* @return mixed
*/
public function OBJECT($subcommand, $arguments = array())
{
array_unshift($arguments, $subcommand);
return $this->__call('OBJECT', $arguments);
}
/** Listen for all requests received by the server in real time */
public function MONITOR()
{
return $this->_send(array('MONITOR'));
}
/** Get the UNIX time stamp of the last successful save to disk Ping the server */
public function LASTSAVE()
{
return $this->_send(array('LASTSAVE'));
}
/** Ping the server */
public function PING()
{
return $this->_send(array('PING'));
}
/**
* Echo the given string
* @param string $message
* @return string
*/
public function ECHO_($message)
{
return $this->_send(array('ECHO', $message));
}
/** Make the server crash */
public function DEBUG_SEGFAULT()
{
return $this->_send(array('DEBUG', 'SEGFAULT'));
}
/**
* Get debugging information about a key
* @param string $key
* @return mixed
*/
public function DEBUG_OBJECT($key)
{
return $this->_send(array('DEBUG', 'OBJECT', $key));
}
/**
* Count the number of set bits (population counting) in a string.
* By default all the bytes contained in the string are examined.
* It is possible to specify the counting operation only in an interval passing the additional arguments start and end.
* @param string $key
* @param int $start
* @param int $end
* @return int
*/
public function BITCOUNT($key, $start = 0, $end = 0)
{
if ($start > 0 || $end > 0)
{
return $this->_send(array('BITCOUNT', $key, $start, $end));
}
return $this->_send(array('BITCOUNT', $key));
}
/**
* Perform a bitwise operation between multiple keys (containing string values) and store the result in the destination key.