Skip to content

Commit bc458d9

Browse files
committed
More command refactoring.
1 parent b12a48b commit bc458d9

File tree

1 file changed

+7
-58
lines changed

1 file changed

+7
-58
lines changed

redis.c

Lines changed: 7 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -2818,73 +2818,22 @@ PHP_METHOD(Redis, zRangeByScore)
28182818
}
28192819
}
28202820

2821-
#define BASIC_FORMAT\
2822-
"$13" _NL\
2823-
"ZRANGEBYSCORE" _NL\
2824-
\
2825-
"$%d" _NL /* key_len */\
2826-
"%s" _NL /* key */\
2827-
\
2828-
"$%d" _NL /* start_len */\
2829-
"%s" _NL /* start */\
2830-
\
2831-
"$%d" _NL /* end_len */\
2832-
"%s" _NL /* end */
2833-
#define BASIC_FORMAT_WITH_LIMIT BASIC_FORMAT\
2834-
"$5" _NL\
2835-
"LIMIT" _NL\
2836-
\
2837-
"$%d" _NL /* limit_low_len */\
2838-
"%d" _NL /* limit_low */\
2839-
\
2840-
"$%d" _NL /* limit_high_len */\
2841-
"%d" _NL /* limit_high */
2842-
28432821
if(withscores) {
28442822
if(has_limit) {
2845-
cmd_len = redis_cmd_format(&cmd,
2846-
"*8" _NL
2847-
BASIC_FORMAT_WITH_LIMIT
2848-
"$10" _NL
2849-
"WITHSCORES" _NL
2850-
, key_len, key, key_len
2851-
, start_len, start, start_len
2852-
, end_len, end, end_len
2853-
, integer_length(limit_low), limit_low
2854-
, integer_length(limit_high), limit_high);
2823+
cmd_len = redis_cmd_format_static(&cmd, "ZRANGEBYSCORE", "ssssdds",
2824+
key, key_len, start, start_len, end, end_len, "LIMIT", 5, limit_low, limit_high, "WITHSCORES", 10);
28552825
} else {
2856-
cmd_len = redis_cmd_format(&cmd,
2857-
"*5" _NL
2858-
BASIC_FORMAT
2859-
"$10" _NL
2860-
"WITHSCORES" _NL
2861-
, key_len, key, key_len
2862-
, start_len, start, start_len
2863-
, end_len, end, end_len);
2826+
cmd_len = redis_cmd_format_static(&cmd, "ZRANGEBYSCORE", "ssss",
2827+
key, key_len, start, start_len, end, end_len, "WITHSCORES", 10);
28642828
}
28652829
} else {
2866-
28672830
if(has_limit) {
2868-
2869-
cmd_len = redis_cmd_format(&cmd,
2870-
"*7" _NL
2871-
BASIC_FORMAT_WITH_LIMIT
2872-
, key_len, key, key_len
2873-
, start_len, start, start_len
2874-
, end_len, end, end_len
2875-
, integer_length(limit_low), limit_low
2876-
, integer_length(limit_high), limit_high);
2831+
cmd_len = redis_cmd_format_static(&cmd, "ZRANGEBYSCORE", "ssssdd",
2832+
key, key_len, start, start_len, end, end_len, "LIMIT", 5, limit_low, limit_high);
28772833
} else {
2878-
cmd_len = redis_cmd_format(&cmd,
2879-
"*4" _NL
2880-
BASIC_FORMAT
2881-
, key_len, key, key_len
2882-
, start_len, start, start_len
2883-
, end_len, end, end_len);
2834+
cmd_len = redis_cmd_format_static(&cmd, "ZRANGEBYSCORE", "sss", key, key_len, start, start_len, end, end_len);
28842835
}
28852836
}
2886-
#undef BASIC_FORMAT
2887-
#undef BASIC_FORMAT_WITH_LIMIT
28882837

28892838
REDIS_PROCESS_REQUEST(redis_sock, cmd, cmd_len);
28902839
if(withscores) {

0 commit comments

Comments
 (0)