-
Notifications
You must be signed in to change notification settings - Fork 2k
Expand file tree
/
Copy pathnc_redis.c
More file actions
3426 lines (2890 loc) · 97.8 KB
/
Copy pathnc_redis.c
File metadata and controls
3426 lines (2890 loc) · 97.8 KB
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
/*
* twemproxy - A fast and lightweight proxy for memcached protocol.
* Copyright (C) 2011 Twitter, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include <stdio.h>
#include <ctype.h>
#include <math.h>
#include <nc_core.h>
#include <nc_proto.h>
#define RSP_STRING(ACTION) \
ACTION( ok, "+OK\r\n" ) \
ACTION( pong, "+PONG\r\n" ) \
ACTION( invalid_password, "-ERR invalid password\r\n" ) \
ACTION( auth_required, "-NOAUTH Authentication required\r\n" ) \
ACTION( no_password, "-ERR Client sent AUTH, but no password is set\r\n" ) \
#define DEFINE_ACTION(_var, _str) static struct string rsp_##_var = string(_str);
RSP_STRING( DEFINE_ACTION )
#undef DEFINE_ACTION
static rstatus_t redis_handle_auth_req(struct msg *request, struct msg *response);
/*
* Return true, if the redis command take no key, otherwise
* return false
*/
static bool
redis_argz(const struct msg *r)
{
switch (r->type) {
/* TODO: PING has an optional argument, emulate that? */
case MSG_REQ_REDIS_PING:
case MSG_REQ_REDIS_QUIT:
case MSG_REQ_REDIS_COMMAND:
return true;
default:
break;
}
return false;
}
/*
* Return true, if the redis command accepts no arguments, otherwise
* return false
*/
static bool
redis_arg0(const struct msg *r)
{
switch (r->type) {
case MSG_REQ_REDIS_PERSIST:
case MSG_REQ_REDIS_PTTL:
case MSG_REQ_REDIS_TTL:
case MSG_REQ_REDIS_TYPE:
case MSG_REQ_REDIS_DUMP:
case MSG_REQ_REDIS_DECR:
case MSG_REQ_REDIS_GET:
case MSG_REQ_REDIS_GETDEL:
case MSG_REQ_REDIS_INCR:
case MSG_REQ_REDIS_STRLEN:
case MSG_REQ_REDIS_HGETALL:
case MSG_REQ_REDIS_HKEYS:
case MSG_REQ_REDIS_HLEN:
case MSG_REQ_REDIS_HVALS:
case MSG_REQ_REDIS_LLEN:
case MSG_REQ_REDIS_SCARD:
case MSG_REQ_REDIS_SMEMBERS:
case MSG_REQ_REDIS_ZCARD:
/* TODO: Support emulating 2-arg username+password auth by just checking password? */
case MSG_REQ_REDIS_AUTH:
return true;
default:
break;
}
return false;
}
/*
* Return true, if the redis command accepts exactly 1 argument, otherwise
* return false
*/
static bool
redis_arg1(const struct msg *r)
{
switch (r->type) {
case MSG_REQ_REDIS_EXPIRE:
case MSG_REQ_REDIS_EXPIREAT:
case MSG_REQ_REDIS_PEXPIRE:
case MSG_REQ_REDIS_PEXPIREAT:
case MSG_REQ_REDIS_MOVE:
case MSG_REQ_REDIS_APPEND:
case MSG_REQ_REDIS_DECRBY:
case MSG_REQ_REDIS_GETBIT:
case MSG_REQ_REDIS_GETSET:
case MSG_REQ_REDIS_INCRBY:
case MSG_REQ_REDIS_INCRBYFLOAT:
case MSG_REQ_REDIS_SETNX:
case MSG_REQ_REDIS_HEXISTS:
case MSG_REQ_REDIS_HGET:
case MSG_REQ_REDIS_HSTRLEN:
case MSG_REQ_REDIS_LINDEX:
case MSG_REQ_REDIS_RPOPLPUSH:
case MSG_REQ_REDIS_SISMEMBER:
case MSG_REQ_REDIS_ZRANK:
case MSG_REQ_REDIS_ZREVRANK:
case MSG_REQ_REDIS_ZSCORE:
return true;
default:
break;
}
return false;
}
/*
* Return true, if the redis command accepts exactly 2 arguments, otherwise
* return false
*/
static bool
redis_arg2(const struct msg *r)
{
switch (r->type) {
case MSG_REQ_REDIS_GETRANGE:
case MSG_REQ_REDIS_PSETEX:
case MSG_REQ_REDIS_SETBIT:
case MSG_REQ_REDIS_SETEX:
case MSG_REQ_REDIS_SETRANGE:
case MSG_REQ_REDIS_HINCRBY:
case MSG_REQ_REDIS_HINCRBYFLOAT:
case MSG_REQ_REDIS_HSETNX:
case MSG_REQ_REDIS_LRANGE:
case MSG_REQ_REDIS_LREM:
case MSG_REQ_REDIS_LSET:
case MSG_REQ_REDIS_LTRIM:
case MSG_REQ_REDIS_SMOVE:
case MSG_REQ_REDIS_ZCOUNT:
case MSG_REQ_REDIS_ZLEXCOUNT:
case MSG_REQ_REDIS_ZINCRBY:
case MSG_REQ_REDIS_ZREMRANGEBYLEX:
case MSG_REQ_REDIS_ZREMRANGEBYRANK:
case MSG_REQ_REDIS_ZREMRANGEBYSCORE:
return true;
default:
break;
}
return false;
}
/*
* Return true, if the redis command accepts exactly 3 arguments, otherwise
* return false
*/
static bool
redis_arg3(const struct msg *r)
{
switch (r->type) {
case MSG_REQ_REDIS_LINSERT:
case MSG_REQ_REDIS_LMOVE:
return true;
default:
break;
}
return false;
}
/*
* Return true, if the redis command operates on one key and accepts 0 or more arguments, otherwise
* return false
*/
static bool
redis_argn(const struct msg *r)
{
switch (r->type) {
case MSG_REQ_REDIS_SORT:
case MSG_REQ_REDIS_COPY:
case MSG_REQ_REDIS_BITCOUNT:
case MSG_REQ_REDIS_BITPOS:
case MSG_REQ_REDIS_BITFIELD:
/* TODO: Support REDIS_BITOP operation destkey key ... and add tests - this requires handling key in a position other than the first one */
case MSG_REQ_REDIS_EXISTS:
case MSG_REQ_REDIS_GETEX:
case MSG_REQ_REDIS_SET:
case MSG_REQ_REDIS_HDEL:
case MSG_REQ_REDIS_HMGET:
case MSG_REQ_REDIS_HMSET:
case MSG_REQ_REDIS_HSCAN:
case MSG_REQ_REDIS_HSET:
case MSG_REQ_REDIS_HRANDFIELD:
case MSG_REQ_REDIS_LPUSH:
case MSG_REQ_REDIS_LPUSHX:
case MSG_REQ_REDIS_RPUSH:
case MSG_REQ_REDIS_RPUSHX:
case MSG_REQ_REDIS_LPOP:
case MSG_REQ_REDIS_RPOP:
case MSG_REQ_REDIS_LPOS:
case MSG_REQ_REDIS_SADD:
case MSG_REQ_REDIS_SDIFF:
case MSG_REQ_REDIS_SDIFFSTORE:
case MSG_REQ_REDIS_SINTER:
case MSG_REQ_REDIS_SINTERSTORE:
case MSG_REQ_REDIS_SREM:
case MSG_REQ_REDIS_SUNION:
case MSG_REQ_REDIS_SUNIONSTORE:
case MSG_REQ_REDIS_SRANDMEMBER:
case MSG_REQ_REDIS_SSCAN:
case MSG_REQ_REDIS_SPOP:
case MSG_REQ_REDIS_SMISMEMBER:
case MSG_REQ_REDIS_PFADD:
case MSG_REQ_REDIS_PFMERGE:
case MSG_REQ_REDIS_PFCOUNT:
case MSG_REQ_REDIS_ZADD:
case MSG_REQ_REDIS_ZDIFF:
case MSG_REQ_REDIS_ZDIFFSTORE:
case MSG_REQ_REDIS_ZINTER:
case MSG_REQ_REDIS_ZINTERSTORE:
case MSG_REQ_REDIS_ZMSCORE:
case MSG_REQ_REDIS_ZPOPMAX:
case MSG_REQ_REDIS_ZPOPMIN:
case MSG_REQ_REDIS_ZRANDMEMBER:
case MSG_REQ_REDIS_ZRANGE:
case MSG_REQ_REDIS_ZRANGEBYLEX:
case MSG_REQ_REDIS_ZRANGEBYSCORE:
case MSG_REQ_REDIS_ZRANGESTORE:
case MSG_REQ_REDIS_ZREM:
case MSG_REQ_REDIS_ZREVRANGE:
case MSG_REQ_REDIS_ZREVRANGEBYLEX:
case MSG_REQ_REDIS_ZREVRANGEBYSCORE:
case MSG_REQ_REDIS_ZSCAN:
case MSG_REQ_REDIS_ZUNION:
case MSG_REQ_REDIS_ZUNIONSTORE:
case MSG_REQ_REDIS_GEODIST:
case MSG_REQ_REDIS_GEOPOS:
case MSG_REQ_REDIS_GEOHASH:
case MSG_REQ_REDIS_GEOADD:
case MSG_REQ_REDIS_GEORADIUS:
case MSG_REQ_REDIS_GEORADIUSBYMEMBER:
case MSG_REQ_REDIS_GEOSEARCH:
case MSG_REQ_REDIS_GEOSEARCHSTORE:
case MSG_REQ_REDIS_RESTORE:
case MSG_REQ_REDIS_SCRIPT:
return true;
default:
break;
}
return false;
}
/*
* Return true, if the redis command is a vector command accepting one or
* more keys, otherwise return false
*/
static bool
redis_argx(const struct msg *r)
{
switch (r->type) {
case MSG_REQ_REDIS_MGET:
case MSG_REQ_REDIS_DEL:
case MSG_REQ_REDIS_UNLINK:
case MSG_REQ_REDIS_TOUCH:
return true;
default:
break;
}
return false;
}
/*
* Return true, if the redis command is a vector command accepting one or
* more key-value pairs, otherwise return false
*/
static bool
redis_argkvx(const struct msg *r)
{
switch (r->type) {
case MSG_REQ_REDIS_MSET:
return true;
default:
break;
}
return false;
}
/*
* Return true, if the redis command is either EVAL or EVALSHA. These commands
* have a special format with exactly 2 arguments, followed by one or more keys,
* followed by zero or more arguments (the documentation online seems to suggest
* that at least one argument is required, but that shouldn't be the case).
*/
static bool
redis_argeval(const struct msg *r)
{
switch (r->type) {
case MSG_REQ_REDIS_EVAL:
case MSG_REQ_REDIS_EVALSHA:
return true;
default:
break;
}
return false;
}
static bool
redis_nokey(const struct msg *r)
{
switch (r->type) {
case MSG_REQ_REDIS_LOLWUT:
return true;
default:
break;
}
return false;
}
/*
* Return true, if the redis response is an error response i.e. a simple
* string whose first character is '-', otherwise return false.
*/
static bool
redis_error(const struct msg *r)
{
switch (r->type) {
case MSG_RSP_REDIS_ERROR:
case MSG_RSP_REDIS_ERROR_ERR:
case MSG_RSP_REDIS_ERROR_OOM:
case MSG_RSP_REDIS_ERROR_BUSY:
case MSG_RSP_REDIS_ERROR_NOAUTH:
case MSG_RSP_REDIS_ERROR_LOADING:
case MSG_RSP_REDIS_ERROR_BUSYKEY:
case MSG_RSP_REDIS_ERROR_MISCONF:
case MSG_RSP_REDIS_ERROR_NOSCRIPT:
case MSG_RSP_REDIS_ERROR_READONLY:
case MSG_RSP_REDIS_ERROR_WRONGTYPE:
case MSG_RSP_REDIS_ERROR_EXECABORT:
case MSG_RSP_REDIS_ERROR_MASTERDOWN:
case MSG_RSP_REDIS_ERROR_NOREPLICAS:
return true;
default:
break;
}
return false;
}
/*
* Reference: http://redis.io/topics/protocol
*
* Redis >= 1.2 uses the unified protocol to send requests to the Redis
* server. In the unified protocol all the arguments sent to the server
* are binary safe and every request has the following general form:
*
* *<number of arguments> CR LF
* $<number of bytes of argument 1> CR LF
* <argument data> CR LF
* ...
* $<number of bytes of argument N> CR LF
* <argument data> CR LF
*
* Before the unified request protocol, redis protocol for requests supported
* the following commands
* 1). Inline commands: simple commands where arguments are just space
* separated strings. No binary safeness is possible.
* 2). Bulk commands: bulk commands are exactly like inline commands, but
* the last argument is handled in a special way in order to allow for
* a binary-safe last argument.
*
* Nutcracker only supports the Redis unified protocol for requests.
*/
void
redis_parse_req(struct msg *r)
{
struct mbuf *b;
uint8_t *p, *m;
uint8_t ch;
enum {
SW_START,
SW_NARG,
SW_NARG_LF,
SW_REQ_TYPE_LEN,
SW_REQ_TYPE_LEN_LF,
SW_REQ_TYPE,
SW_REQ_TYPE_LF,
SW_KEY_LEN,
SW_KEY_LEN_LF,
SW_KEY,
SW_KEY_LF,
SW_ARG1_LEN,
SW_ARG1_LEN_LF,
SW_ARG1,
SW_ARG1_LF,
SW_ARG2_LEN,
SW_ARG2_LEN_LF,
SW_ARG2,
SW_ARG2_LF,
SW_ARG3_LEN,
SW_ARG3_LEN_LF,
SW_ARG3,
SW_ARG3_LF,
SW_ARGN_LEN,
SW_ARGN_LEN_LF,
SW_ARGN,
SW_ARGN_LF,
SW_SENTINEL
} state;
state = r->state;
b = STAILQ_LAST(&r->mhdr, mbuf, next);
ASSERT(r->request);
ASSERT(state >= SW_START && state < SW_SENTINEL);
ASSERT(b != NULL);
ASSERT(b->pos <= b->last);
/* validate the parsing maker */
ASSERT(r->pos != NULL);
ASSERT(r->pos >= b->pos && r->pos <= b->last);
for (p = r->pos; p < b->last; p++) {
ch = *p;
switch (state) {
case SW_START:
ASSERT(r->token == NULL);
if (ch != '*') {
/* redis commands are always arrays */
goto error;
}
r->token = p;
/* req_start <- p */
r->narg_start = p;
r->rnarg = 0;
state = SW_NARG;
break;
case SW_NARG:
/* SW_NARG: The number of arguments in the redis command array */
ASSERT(r->token != NULL);
if (isdigit(ch)) {
r->rnarg = r->rnarg * 10 + (uint32_t)(ch - '0');
} else if (ch == CR) {
if (r->rnarg == 0) {
goto error;
}
r->narg = r->rnarg;
r->narg_end = p;
r->token = NULL;
state = SW_NARG_LF;
} else {
goto error;
}
break;
case SW_NARG_LF:
switch (ch) {
case LF:
state = SW_REQ_TYPE_LEN;
break;
default:
goto error;
}
break;
case SW_REQ_TYPE_LEN:
if (r->token == NULL) {
if (ch != '$') {
goto error;
}
r->token = p;
r->rlen = 0;
} else if (isdigit(ch)) {
r->rlen = r->rlen * 10 + (uint32_t)(ch - '0');
} else if (ch == CR) {
if (r->rlen == 0 || r->rnarg == 0) {
goto error;
}
r->rnarg--;
r->token = NULL;
state = SW_REQ_TYPE_LEN_LF;
} else {
goto error;
}
break;
case SW_REQ_TYPE_LEN_LF:
switch (ch) {
case LF:
state = SW_REQ_TYPE;
break;
default:
goto error;
}
break;
case SW_REQ_TYPE:
if (r->token == NULL) {
r->token = p;
}
m = r->token + r->rlen;
if (m >= b->last) {
m = b->last - 1;
p = m;
break;
}
if (*m != CR) {
goto error;
}
p = m; /* move forward by rlen bytes */
r->rlen = 0;
m = r->token;
r->token = NULL;
r->type = MSG_UNKNOWN;
switch (p - m) {
case 3:
if (str3icmp(m, 'g', 'e', 't')) {
r->type = MSG_REQ_REDIS_GET;
break;
}
if (str3icmp(m, 's', 'e', 't')) {
r->type = MSG_REQ_REDIS_SET;
break;
}
if (str3icmp(m, 't', 't', 'l')) {
r->type = MSG_REQ_REDIS_TTL;
break;
}
if (str3icmp(m, 'd', 'e', 'l')) {
r->type = MSG_REQ_REDIS_DEL;
break;
}
break;
case 4:
if (str4icmp(m, 'p', 't', 't', 'l')) {
r->type = MSG_REQ_REDIS_PTTL;
break;
}
if (str4icmp(m, 'd', 'e', 'c', 'r')) {
r->type = MSG_REQ_REDIS_DECR;
break;
}
if (str4icmp(m, 'd', 'u', 'm', 'p')) {
r->type = MSG_REQ_REDIS_DUMP;
break;
}
if (str4icmp(m, 'h', 'd', 'e', 'l')) {
r->type = MSG_REQ_REDIS_HDEL;
break;
}
if (str4icmp(m, 'h', 'g', 'e', 't')) {
r->type = MSG_REQ_REDIS_HGET;
break;
}
if (str4icmp(m, 'h', 'l', 'e', 'n')) {
r->type = MSG_REQ_REDIS_HLEN;
break;
}
if (str4icmp(m, 'h', 's', 'e', 't')) {
r->type = MSG_REQ_REDIS_HSET;
break;
}
if (str4icmp(m, 'i', 'n', 'c', 'r')) {
r->type = MSG_REQ_REDIS_INCR;
break;
}
if (str4icmp(m, 'l', 'l', 'e', 'n')) {
r->type = MSG_REQ_REDIS_LLEN;
break;
}
if (str4icmp(m, 'l', 'p', 'o', 'p')) {
r->type = MSG_REQ_REDIS_LPOP;
break;
}
if (str4icmp(m, 'l', 'p', 'o', 's')) {
r->type = MSG_REQ_REDIS_LPOS;
break;
}
if (str4icmp(m, 'l', 'r', 'e', 'm')) {
r->type = MSG_REQ_REDIS_LREM;
break;
}
if (str4icmp(m, 'l', 's', 'e', 't')) {
r->type = MSG_REQ_REDIS_LSET;
break;
}
if (str4icmp(m, 'r', 'p', 'o', 'p')) {
r->type = MSG_REQ_REDIS_RPOP;
break;
}
if (str4icmp(m, 's', 'a', 'd', 'd')) {
r->type = MSG_REQ_REDIS_SADD;
break;
}
if (str4icmp(m, 's', 'p', 'o', 'p')) {
r->type = MSG_REQ_REDIS_SPOP;
break;
}
if (str4icmp(m, 's', 'r', 'e', 'm')) {
r->type = MSG_REQ_REDIS_SREM;
break;
}
if (str4icmp(m, 't', 'y', 'p', 'e')) {
r->type = MSG_REQ_REDIS_TYPE;
break;
}
if (str4icmp(m, 'm', 'g', 'e', 't')) {
r->type = MSG_REQ_REDIS_MGET;
break;
}
if (str4icmp(m, 'm', 's', 'e', 't')) {
r->type = MSG_REQ_REDIS_MSET;
break;
}
if (str4icmp(m, 'z', 'a', 'd', 'd')) {
r->type = MSG_REQ_REDIS_ZADD;
break;
}
if (str4icmp(m, 'z', 'r', 'e', 'm')) {
r->type = MSG_REQ_REDIS_ZREM;
break;
}
if (str4icmp(m, 'e', 'v', 'a', 'l')) {
r->type = MSG_REQ_REDIS_EVAL;
break;
}
if (str4icmp(m, 's', 'o', 'r', 't')) {
r->type = MSG_REQ_REDIS_SORT;
break;
}
if (str4icmp(m, 'p', 'i', 'n', 'g')) {
r->type = MSG_REQ_REDIS_PING;
r->noforward = 1;
break;
}
if (str4icmp(m, 'q', 'u', 'i', 't')) {
r->type = MSG_REQ_REDIS_QUIT;
r->quit = 1;
break;
}
if (str4icmp(m, 'a', 'u', 't', 'h')) {
r->type = MSG_REQ_REDIS_AUTH;
r->noforward = 1;
break;
}
if (str4icmp(m, 'm', 'o', 'v', 'e')) {
r->type = MSG_REQ_REDIS_MOVE;
r->noforward = 1;
break;
}
if (str4icmp(m, 'c', 'o', 'p', 'y')) {
r->type = MSG_REQ_REDIS_COPY;
break;
}
break;
case 5:
if (str5icmp(m, 'h', 'k', 'e', 'y', 's')) {
r->type = MSG_REQ_REDIS_HKEYS;
break;
}
if (str5icmp(m, 'h', 'm', 'g', 'e', 't')) {
r->type = MSG_REQ_REDIS_HMGET;
break;
}
if (str5icmp(m, 'h', 'm', 's', 'e', 't')) {
r->type = MSG_REQ_REDIS_HMSET;
break;
}
if (str5icmp(m, 'h', 'v', 'a', 'l', 's')) {
r->type = MSG_REQ_REDIS_HVALS;
break;
}
if (str5icmp(m, 'h', 's', 'c', 'a', 'n')) {
r->type = MSG_REQ_REDIS_HSCAN;
break;
}
if (str5icmp(m, 'l', 'p', 'u', 's', 'h')) {
r->type = MSG_REQ_REDIS_LPUSH;
break;
}
if (str5icmp(m, 'l', 't', 'r', 'i', 'm')) {
r->type = MSG_REQ_REDIS_LTRIM;
break;
}
if (str5icmp(m, 'r', 'p', 'u', 's', 'h')) {
r->type = MSG_REQ_REDIS_RPUSH;
break;
}
if (str5icmp(m, 's', 'c', 'a', 'r', 'd')) {
r->type = MSG_REQ_REDIS_SCARD;
break;
}
if (str5icmp(m, 's', 'd', 'i', 'f', 'f')) {
r->type = MSG_REQ_REDIS_SDIFF;
break;
}
if (str5icmp(m, 's', 'e', 't', 'e', 'x')) {
r->type = MSG_REQ_REDIS_SETEX;
break;
}
if (str5icmp(m, 's', 'e', 't', 'n', 'x')) {
r->type = MSG_REQ_REDIS_SETNX;
break;
}
if (str5icmp(m, 's', 'm', 'o', 'v', 'e')) {
r->type = MSG_REQ_REDIS_SMOVE;
break;
}
if (str5icmp(m, 's', 's', 'c', 'a', 'n')) {
r->type = MSG_REQ_REDIS_SSCAN;
break;
}
if (str5icmp(m, 'z', 'c', 'a', 'r', 'd')) {
r->type = MSG_REQ_REDIS_ZCARD;
break;
}
if (str5icmp(m, 'z', 'd', 'i', 'f', 'f')) {
r->type = MSG_REQ_REDIS_ZDIFF;
break;
}
if (str5icmp(m, 'z', 'r', 'a', 'n', 'k')) {
r->type = MSG_REQ_REDIS_ZRANK;
break;
}
if (str5icmp(m, 'z', 's', 'c', 'a', 'n')) {
r->type = MSG_REQ_REDIS_ZSCAN;
break;
}
if (str5icmp(m, 'p', 'f', 'a', 'd', 'd')) {
r->type = MSG_REQ_REDIS_PFADD;
break;
}
if (str5icmp(m, 'g', 'e', 't', 'e', 'x')) {
r->type = MSG_REQ_REDIS_GETEX;
break;
}
if (str5icmp(m, 't', 'o', 'u', 'c', 'h')) {
r->type = MSG_REQ_REDIS_TOUCH;
break;
}
if (str5icmp(m, 'l', 'm', 'o', 'v', 'e')) {
r->type = MSG_REQ_REDIS_LMOVE;
break;
}
break;
case 6:
if (str6icmp(m, 'a', 'p', 'p', 'e', 'n', 'd')) {
r->type = MSG_REQ_REDIS_APPEND;
break;
}
if (str6icmp(m, 'b', 'i', 't', 'p', 'o', 's')) {
r->type = MSG_REQ_REDIS_BITPOS;
break;
}
if (str6icmp(m, 'd', 'e', 'c', 'r', 'b', 'y')) {
r->type = MSG_REQ_REDIS_DECRBY;
break;
}
if (str6icmp(m, 'e', 'x', 'i', 's', 't', 's')) {
r->type = MSG_REQ_REDIS_EXISTS;
break;
}
if (str6icmp(m, 'e', 'x', 'p', 'i', 'r', 'e')) {
r->type = MSG_REQ_REDIS_EXPIRE;
break;
}
if (str6icmp(m, 'g', 'e', 't', 'b', 'i', 't')) {
r->type = MSG_REQ_REDIS_GETBIT;
break;
}
if (str6icmp(m, 'g', 'e', 't', 's', 'e', 't')) {
r->type = MSG_REQ_REDIS_GETSET;
break;
}
if (str6icmp(m, 'p', 's', 'e', 't', 'e', 'x')) {
r->type = MSG_REQ_REDIS_PSETEX;
break;
}
if (str6icmp(m, 'h', 's', 'e', 't', 'n', 'x')) {
r->type = MSG_REQ_REDIS_HSETNX;
break;
}
if (str6icmp(m, 'i', 'n', 'c', 'r', 'b', 'y')) {
r->type = MSG_REQ_REDIS_INCRBY;
break;
}
if (str6icmp(m, 'l', 'i', 'n', 'd', 'e', 'x')) {
r->type = MSG_REQ_REDIS_LINDEX;
break;
}
if (str6icmp(m, 'l', 'p', 'u', 's', 'h', 'x')) {
r->type = MSG_REQ_REDIS_LPUSHX;
break;
}
if (str6icmp(m, 'l', 'r', 'a', 'n', 'g', 'e')) {
r->type = MSG_REQ_REDIS_LRANGE;
break;
}
if (str6icmp(m, 'r', 'p', 'u', 's', 'h', 'x')) {
r->type = MSG_REQ_REDIS_RPUSHX;
break;
}
if (str6icmp(m, 's', 'e', 't', 'b', 'i', 't')) {
r->type = MSG_REQ_REDIS_SETBIT;
break;
}
if (str6icmp(m, 's', 'i', 'n', 't', 'e', 'r')) {
r->type = MSG_REQ_REDIS_SINTER;
break;
}
if (str6icmp(m, 's', 't', 'r', 'l', 'e', 'n')) {
r->type = MSG_REQ_REDIS_STRLEN;
break;
}
if (str6icmp(m, 's', 'u', 'n', 'i', 'o', 'n')) {
r->type = MSG_REQ_REDIS_SUNION;
break;
}
if (str6icmp(m, 'z', 'c', 'o', 'u', 'n', 't')) {
r->type = MSG_REQ_REDIS_ZCOUNT;
break;
}
if (str6icmp(m, 'z', 'r', 'a', 'n', 'g', 'e')) {
r->type = MSG_REQ_REDIS_ZRANGE;
break;
}
if (str6icmp(m, 'z', 's', 'c', 'o', 'r', 'e')) {
r->type = MSG_REQ_REDIS_ZSCORE;
break;
}
if (str6icmp(m, 'g', 'e', 'o', 'p', 'o', 's')) {
r->type = MSG_REQ_REDIS_GEOPOS;
break;
}
if (str6icmp(m, 'g', 'e', 'o', 'a', 'd', 'd')) {
r->type = MSG_REQ_REDIS_GEOADD;
break;
}
if (str6icmp(m, 'g', 'e', 't', 'd', 'e', 'l')) {
r->type = MSG_REQ_REDIS_GETDEL;
break;
}
if (str6icmp(m, 'z', 'u', 'n', 'i', 'o', 'n')) {
r->type = MSG_REQ_REDIS_ZUNION;
break;
}
if (str6icmp(m, 'z', 'i', 'n', 't', 'e', 'r')) {
r->type = MSG_REQ_REDIS_ZINTER;
break;
}
if (str6icmp(m, 'u', 'n', 'l', 'i', 'n', 'k')) {