-
Notifications
You must be signed in to change notification settings - Fork 0
/
redis-cli-bare.patch
272 lines (259 loc) · 7.96 KB
/
redis-cli-bare.patch
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
*** ./redis-cli.c Thu Sep 9 16:53:16 2010
--- ../redis-2.0.2/redis-cli.c Tue Nov 16 14:51:11 2010
***************
*** 44,49 ****
--- 44,50 ----
#include "zmalloc.h"
#include "linenoise.h"
+ #define REDIS_CLI_VERSION "2.0.4"
#define REDIS_CMD_INLINE 1
#define REDIS_CMD_BULK 2
#define REDIS_CMD_MULTIBULK 4
***************
*** 62,67 ****
--- 63,69 ----
int raw_output; /* output mode per command */
int tty; /* flag for default output format */
int stdinarg; /* get last arg from stdin. (-x option) */
+ int bare_output; /* bare, computer parsable output */
char mb_sep;
char *auth;
char *historyfile;
***************
*** 119,146 ****
}
static void printStringRepr(char *s, int len) {
! printf("\"");
! while(len--) {
! switch(*s) {
! case '\\':
! case '"':
! printf("\\%c",*s);
! break;
! case '\n': printf("\\n"); break;
! case '\r': printf("\\r"); break;
! case '\t': printf("\\t"); break;
! case '\a': printf("\\a"); break;
! case '\b': printf("\\b"); break;
! default:
! if (isprint(*s))
! printf("%c",*s);
! else
! printf("\\x%02x",(unsigned char)*s);
! break;
! }
! s++;
! }
! printf("\"");
}
static int cliReadBulkReply(int fd) {
--- 121,149 ----
}
static void printStringRepr(char *s, int len) {
! if (!config.bare_output) printf("\"");
! while(len--) {
! if (!config.bare_output)
! switch(*s) {
! case '\\':
! case '"':
! printf("\\%c",*s);
! break;
! case '\n': printf("\\n"); break;
! case '\r': printf("\\r"); break;
! case '\t': printf("\\t"); break;
! case '\a': printf("\\a"); break;
! case '\b': printf("\\b"); break;
! default:
! if (isprint(*s))
! printf("%c",*s);
! else
! printf("\\x%02x",(unsigned char)*s);
! break;
! } else printf("%c", *s);
! s++;
! }
! if (!config.bare_output) printf("\"");
}
static int cliReadBulkReply(int fd) {
***************
*** 152,158 ****
bulklen = atoi(replylen);
if (bulklen == -1) {
sdsfree(replylen);
! printf("(nil)\n");
return 0;
}
reply = zmalloc(bulklen);
--- 155,161 ----
bulklen = atoi(replylen);
if (bulklen == -1) {
sdsfree(replylen);
! if (!config.bare_output) printf("(nil)\n");
return 0;
}
reply = zmalloc(bulklen);
***************
*** 181,194 ****
elements = atoi(replylen);
if (elements == -1) {
sdsfree(replylen);
! printf("(nil)\n");
return 0;
}
if (elements == 0) {
! printf("(empty list or set)\n");
}
while(elements--) {
! if (config.tty) printf("%d. ", c);
if (cliReadReply(fd)) retval = 1;
if (elements) printf("%c",config.mb_sep);
c++;
--- 184,197 ----
elements = atoi(replylen);
if (elements == -1) {
sdsfree(replylen);
! if (!config.bare_output) printf("(nil)\n");
return 0;
}
if (elements == 0) {
! if (!config.bare_output) printf("(empty list or set)\n");
}
while(elements--) {
! if (config.tty && !config.bare_output) printf("%d. ", c);
if (cliReadReply(fd)) retval = 1;
if (elements) printf("%c",config.mb_sep);
c++;
***************
*** 213,225 ****
}
switch(type) {
case '-':
! if (config.tty) printf("(error) ");
cliReadSingleLineReply(fd,0);
return 1;
case '+':
return cliReadSingleLineReply(fd,0);
case ':':
! if (config.tty) printf("(integer) ");
return cliReadSingleLineReply(fd,0);
case '$':
return cliReadBulkReply(fd);
--- 216,228 ----
}
switch(type) {
case '-':
! if (config.tty && !config.bare_output) printf("(error) ");
cliReadSingleLineReply(fd,0);
return 1;
case '+':
return cliReadSingleLineReply(fd,0);
case ':':
! if (config.tty && !config.bare_output) printf("(integer) ");
return cliReadSingleLineReply(fd,0);
case '$':
return cliReadBulkReply(fd);
***************
*** 254,260 ****
static void showInteractiveHelp(void) {
printf(
"\n"
! "Welcome to redis-cli 2.0.0!\n"
"Just type any valid Redis command to see a pretty printed output.\n"
"\n"
"It is possible to quote strings, like in:\n"
--- 257,265 ----
static void showInteractiveHelp(void) {
printf(
"\n"
! "Welcome to redis-cli "
! REDIS_CLI_VERSION
! "\n"
"Just type any valid Redis command to see a pretty printed output.\n"
"\n"
"It is possible to quote strings, like in:\n"
***************
*** 307,316 ****
}
if (config.pubsub_mode) {
! printf("Reading messages... (press Ctrl-c to quit)\n");
while (1) {
cliReadReply(fd);
! printf("\n\n");
}
}
--- 312,323 ----
}
if (config.pubsub_mode) {
! if (!config.bare_output) printf("Reading messages... (press Ctrl-c to quit)\n");
while (1) {
cliReadReply(fd);
! if (!config.bare_output) printf("\n");
! printf("\n");
! fflush(stdout);
}
}
***************
*** 337,344 ****
--- 344,355 ----
i++;
} else if (!strcmp(argv[i],"-h") && lastarg) {
usage();
+ } else if (!strcmp(argv[i],"help") && lastarg) {
+ usage();
} else if (!strcmp(argv[i],"-x")) {
config.stdinarg = 1;
+ } else if (!strcmp(argv[i],"-b")) {
+ config.bare_output = 1;
} else if (!strcmp(argv[i],"-p") && !lastarg) {
config.hostport = atoi(argv[i+1]);
i++;
***************
*** 363,369 ****
"automatically used as last argument.\n"
);
} else if (!strcmp(argv[i],"-v")) {
! printf("redis-cli shipped with Redis verison %s\n", "2.0.0");
exit(0);
} else {
break;
--- 374,380 ----
"automatically used as last argument.\n"
);
} else if (!strcmp(argv[i],"-v")) {
! printf("redis-cli shipped with Redis verison %s\n", REDIS_CLI_VERSION);
exit(0);
} else {
break;
***************
*** 390,401 ****
}
static void usage() {
! fprintf(stderr, "usage: redis-cli [-iv] [-h host] [-p port] [-a authpw] [-r repeat_times] [-n db_num] cmd arg1 arg2 arg3 ... argN\n");
fprintf(stderr, "usage: echo \"argN\" | redis-cli -x [options] cmd arg1 arg2 ... arg(N-1)\n\n");
fprintf(stderr, "example: cat /etc/passwd | redis-cli -x set my_passwd\n");
fprintf(stderr, "example: redis-cli get my_passwd\n");
fprintf(stderr, "example: redis-cli -r 100 lpush mylist x\n");
! fprintf(stderr, "\nRun in interactive mode: redis-cli -i or just don't pass any command\n");
exit(1);
}
--- 401,412 ----
}
static void usage() {
! fprintf(stderr, "usage: redis-cli [-vb] [-h host] [-p port] [-a authpw] [-r repeat_times] [-n db_num] cmd arg1 arg2 arg3 ... argN\n");
fprintf(stderr, "usage: echo \"argN\" | redis-cli -x [options] cmd arg1 arg2 ... arg(N-1)\n\n");
fprintf(stderr, "example: cat /etc/passwd | redis-cli -x set my_passwd\n");
fprintf(stderr, "example: redis-cli get my_passwd\n");
fprintf(stderr, "example: redis-cli -r 100 lpush mylist x\n");
! fprintf(stderr, "\nRun in interactive mode: just don't pass any command\n");
exit(1);
}
***************
*** 480,485 ****
--- 491,497 ----
config.monitor_mode = 0;
config.pubsub_mode = 0;
config.raw_output = 0;
+ config.bare_output = 0;
config.stdinarg = 0;
config.auth = NULL;
config.historyfile = NULL;