3 /*-----------------------------------------------------------------------------
5 *----------------------------------------------------------------------------*/
7 int yesnotoi(char *s
) {
8 if (!strcasecmp(s
,"yes")) return 1;
9 else if (!strcasecmp(s
,"no")) return 0;
13 void appendServerSaveParams(time_t seconds
, int changes
) {
14 server
.saveparams
= zrealloc(server
.saveparams
,sizeof(struct saveparam
)*(server
.saveparamslen
+1));
15 server
.saveparams
[server
.saveparamslen
].seconds
= seconds
;
16 server
.saveparams
[server
.saveparamslen
].changes
= changes
;
17 server
.saveparamslen
++;
20 void resetServerSaveParams() {
21 zfree(server
.saveparams
);
22 server
.saveparams
= NULL
;
23 server
.saveparamslen
= 0;
26 /* I agree, this is a very rudimental way to load a configuration...
27 will improve later if the config gets more complex */
28 void loadServerConfig(char *filename
) {
30 char buf
[REDIS_CONFIGLINE_MAX
+1], *err
= NULL
;
34 if (filename
[0] == '-' && filename
[1] == '\0')
37 if ((fp
= fopen(filename
,"r")) == NULL
) {
38 redisLog(REDIS_WARNING
, "Fatal error, can't open config file '%s'", filename
);
43 while(fgets(buf
,REDIS_CONFIGLINE_MAX
+1,fp
) != NULL
) {
49 line
= sdstrim(line
," \t\r\n");
51 /* Skip comments and blank lines*/
52 if (line
[0] == '#' || line
[0] == '\0') {
57 /* Split into arguments */
58 argv
= sdssplitargs(line
,&argc
);
61 /* Execute config directives */
62 if (!strcasecmp(argv
[0],"timeout") && argc
== 2) {
63 server
.maxidletime
= atoi(argv
[1]);
64 if (server
.maxidletime
< 0) {
65 err
= "Invalid timeout value"; goto loaderr
;
67 } else if (!strcasecmp(argv
[0],"port") && argc
== 2) {
68 server
.port
= atoi(argv
[1]);
69 if (server
.port
< 0 || server
.port
> 65535) {
70 err
= "Invalid port"; goto loaderr
;
72 } else if (!strcasecmp(argv
[0],"bind") && argc
== 2) {
73 server
.bindaddr
= zstrdup(argv
[1]);
74 } else if (!strcasecmp(argv
[0],"unixsocket") && argc
== 2) {
75 server
.unixsocket
= zstrdup(argv
[1]);
76 } else if (!strcasecmp(argv
[0],"unixsocketperm") && argc
== 2) {
77 server
.unixsocketperm
= (mode_t
)strtol(argv
[1], NULL
, 8);
78 if (errno
|| server
.unixsocketperm
> 0777) {
79 err
= "Invalid socket file permissions"; goto loaderr
;
81 } else if (!strcasecmp(argv
[0],"save") && argc
== 3) {
82 int seconds
= atoi(argv
[1]);
83 int changes
= atoi(argv
[2]);
84 if (seconds
< 1 || changes
< 0) {
85 err
= "Invalid save parameters"; goto loaderr
;
87 appendServerSaveParams(seconds
,changes
);
88 } else if (!strcasecmp(argv
[0],"dir") && argc
== 2) {
89 if (chdir(argv
[1]) == -1) {
90 redisLog(REDIS_WARNING
,"Can't chdir to '%s': %s",
91 argv
[1], strerror(errno
));
94 } else if (!strcasecmp(argv
[0],"loglevel") && argc
== 2) {
95 if (!strcasecmp(argv
[1],"debug")) server
.verbosity
= REDIS_DEBUG
;
96 else if (!strcasecmp(argv
[1],"verbose")) server
.verbosity
= REDIS_VERBOSE
;
97 else if (!strcasecmp(argv
[1],"notice")) server
.verbosity
= REDIS_NOTICE
;
98 else if (!strcasecmp(argv
[1],"warning")) server
.verbosity
= REDIS_WARNING
;
100 err
= "Invalid log level. Must be one of debug, notice, warning";
103 } else if (!strcasecmp(argv
[0],"logfile") && argc
== 2) {
106 server
.logfile
= zstrdup(argv
[1]);
107 if (!strcasecmp(server
.logfile
,"stdout")) {
108 zfree(server
.logfile
);
109 server
.logfile
= NULL
;
111 if (server
.logfile
) {
112 /* Test if we are able to open the file. The server will not
113 * be able to abort just for this problem later... */
114 logfp
= fopen(server
.logfile
,"a");
116 err
= sdscatprintf(sdsempty(),
117 "Can't open the log file: %s", strerror(errno
));
122 } else if (!strcasecmp(argv
[0],"syslog-enabled") && argc
== 2) {
123 if ((server
.syslog_enabled
= yesnotoi(argv
[1])) == -1) {
124 err
= "argument must be 'yes' or 'no'"; goto loaderr
;
126 } else if (!strcasecmp(argv
[0],"syslog-ident") && argc
== 2) {
127 if (server
.syslog_ident
) zfree(server
.syslog_ident
);
128 server
.syslog_ident
= zstrdup(argv
[1]);
129 } else if (!strcasecmp(argv
[0],"syslog-facility") && argc
== 2) {
133 } validSyslogFacilities
[] = {
135 {"local0", LOG_LOCAL0
},
136 {"local1", LOG_LOCAL1
},
137 {"local2", LOG_LOCAL2
},
138 {"local3", LOG_LOCAL3
},
139 {"local4", LOG_LOCAL4
},
140 {"local5", LOG_LOCAL5
},
141 {"local6", LOG_LOCAL6
},
142 {"local7", LOG_LOCAL7
},
147 for (i
= 0; validSyslogFacilities
[i
].name
; i
++) {
148 if (!strcasecmp(validSyslogFacilities
[i
].name
, argv
[1])) {
149 server
.syslog_facility
= validSyslogFacilities
[i
].value
;
154 if (!validSyslogFacilities
[i
].name
) {
155 err
= "Invalid log facility. Must be one of USER or between LOCAL0-LOCAL7";
158 } else if (!strcasecmp(argv
[0],"databases") && argc
== 2) {
159 server
.dbnum
= atoi(argv
[1]);
160 if (server
.dbnum
< 1) {
161 err
= "Invalid number of databases"; goto loaderr
;
163 } else if (!strcasecmp(argv
[0],"include") && argc
== 2) {
164 loadServerConfig(argv
[1]);
165 } else if (!strcasecmp(argv
[0],"maxclients") && argc
== 2) {
166 server
.maxclients
= atoi(argv
[1]);
167 } else if (!strcasecmp(argv
[0],"maxmemory") && argc
== 2) {
168 server
.maxmemory
= memtoll(argv
[1],NULL
);
169 } else if (!strcasecmp(argv
[0],"maxmemory-policy") && argc
== 2) {
170 if (!strcasecmp(argv
[1],"volatile-lru")) {
171 server
.maxmemory_policy
= REDIS_MAXMEMORY_VOLATILE_LRU
;
172 } else if (!strcasecmp(argv
[1],"volatile-random")) {
173 server
.maxmemory_policy
= REDIS_MAXMEMORY_VOLATILE_RANDOM
;
174 } else if (!strcasecmp(argv
[1],"volatile-ttl")) {
175 server
.maxmemory_policy
= REDIS_MAXMEMORY_VOLATILE_TTL
;
176 } else if (!strcasecmp(argv
[1],"allkeys-lru")) {
177 server
.maxmemory_policy
= REDIS_MAXMEMORY_ALLKEYS_LRU
;
178 } else if (!strcasecmp(argv
[1],"allkeys-random")) {
179 server
.maxmemory_policy
= REDIS_MAXMEMORY_ALLKEYS_RANDOM
;
180 } else if (!strcasecmp(argv
[1],"noeviction")) {
181 server
.maxmemory_policy
= REDIS_MAXMEMORY_NO_EVICTION
;
183 err
= "Invalid maxmemory policy";
186 } else if (!strcasecmp(argv
[0],"maxmemory-samples") && argc
== 2) {
187 server
.maxmemory_samples
= atoi(argv
[1]);
188 if (server
.maxmemory_samples
<= 0) {
189 err
= "maxmemory-samples must be 1 or greater";
192 } else if (!strcasecmp(argv
[0],"slaveof") && argc
== 3) {
193 server
.masterhost
= sdsnew(argv
[1]);
194 server
.masterport
= atoi(argv
[2]);
195 server
.replstate
= REDIS_REPL_CONNECT
;
196 } else if (!strcasecmp(argv
[0],"masterauth") && argc
== 2) {
197 server
.masterauth
= zstrdup(argv
[1]);
198 } else if (!strcasecmp(argv
[0],"slave-serve-stale-data") && argc
== 2) {
199 if ((server
.repl_serve_stale_data
= yesnotoi(argv
[1])) == -1) {
200 err
= "argument must be 'yes' or 'no'"; goto loaderr
;
202 } else if (!strcasecmp(argv
[0],"glueoutputbuf")) {
203 redisLog(REDIS_WARNING
, "Deprecated configuration directive: \"%s\"", argv
[0]);
204 } else if (!strcasecmp(argv
[0],"rdbcompression") && argc
== 2) {
205 if ((server
.rdbcompression
= yesnotoi(argv
[1])) == -1) {
206 err
= "argument must be 'yes' or 'no'"; goto loaderr
;
208 } else if (!strcasecmp(argv
[0],"activerehashing") && argc
== 2) {
209 if ((server
.activerehashing
= yesnotoi(argv
[1])) == -1) {
210 err
= "argument must be 'yes' or 'no'"; goto loaderr
;
212 } else if (!strcasecmp(argv
[0],"daemonize") && argc
== 2) {
213 if ((server
.daemonize
= yesnotoi(argv
[1])) == -1) {
214 err
= "argument must be 'yes' or 'no'"; goto loaderr
;
216 } else if (!strcasecmp(argv
[0],"appendonly") && argc
== 2) {
217 if ((server
.appendonly
= yesnotoi(argv
[1])) == -1) {
218 err
= "argument must be 'yes' or 'no'"; goto loaderr
;
220 } else if (!strcasecmp(argv
[0],"appendfilename") && argc
== 2) {
221 zfree(server
.appendfilename
);
222 server
.appendfilename
= zstrdup(argv
[1]);
223 } else if (!strcasecmp(argv
[0],"no-appendfsync-on-rewrite")
225 if ((server
.no_appendfsync_on_rewrite
= yesnotoi(argv
[1])) == -1) {
226 err
= "argument must be 'yes' or 'no'"; goto loaderr
;
228 } else if (!strcasecmp(argv
[0],"appendfsync") && argc
== 2) {
229 if (!strcasecmp(argv
[1],"no")) {
230 server
.appendfsync
= APPENDFSYNC_NO
;
231 } else if (!strcasecmp(argv
[1],"always")) {
232 server
.appendfsync
= APPENDFSYNC_ALWAYS
;
233 } else if (!strcasecmp(argv
[1],"everysec")) {
234 server
.appendfsync
= APPENDFSYNC_EVERYSEC
;
236 err
= "argument must be 'no', 'always' or 'everysec'";
239 } else if (!strcasecmp(argv
[0],"auto-aof-rewrite-percentage") &&
242 server
.auto_aofrewrite_perc
= atoi(argv
[1]);
243 if (server
.auto_aofrewrite_perc
< 0) {
244 err
= "Invalid negative percentage for AOF auto rewrite";
247 } else if (!strcasecmp(argv
[0],"auto-aof-rewrite-min-size") &&
250 server
.auto_aofrewrite_min_size
= memtoll(argv
[1],NULL
);
251 } else if (!strcasecmp(argv
[0],"requirepass") && argc
== 2) {
252 server
.requirepass
= zstrdup(argv
[1]);
253 } else if (!strcasecmp(argv
[0],"pidfile") && argc
== 2) {
254 zfree(server
.pidfile
);
255 server
.pidfile
= zstrdup(argv
[1]);
256 } else if (!strcasecmp(argv
[0],"dbfilename") && argc
== 2) {
257 zfree(server
.dbfilename
);
258 server
.dbfilename
= zstrdup(argv
[1]);
259 } else if (!strcasecmp(argv
[0],"hash-max-zipmap-entries") && argc
== 2) {
260 server
.hash_max_zipmap_entries
= memtoll(argv
[1], NULL
);
261 } else if (!strcasecmp(argv
[0],"hash-max-zipmap-value") && argc
== 2) {
262 server
.hash_max_zipmap_value
= memtoll(argv
[1], NULL
);
263 } else if (!strcasecmp(argv
[0],"list-max-ziplist-entries") && argc
== 2){
264 server
.list_max_ziplist_entries
= memtoll(argv
[1], NULL
);
265 } else if (!strcasecmp(argv
[0],"list-max-ziplist-value") && argc
== 2) {
266 server
.list_max_ziplist_value
= memtoll(argv
[1], NULL
);
267 } else if (!strcasecmp(argv
[0],"set-max-intset-entries") && argc
== 2) {
268 server
.set_max_intset_entries
= memtoll(argv
[1], NULL
);
269 } else if (!strcasecmp(argv
[0],"zset-max-ziplist-entries") && argc
== 2) {
270 server
.zset_max_ziplist_entries
= memtoll(argv
[1], NULL
);
271 } else if (!strcasecmp(argv
[0],"zset-max-ziplist-value") && argc
== 2) {
272 server
.zset_max_ziplist_value
= memtoll(argv
[1], NULL
);
273 } else if (!strcasecmp(argv
[0],"rename-command") && argc
== 3) {
274 struct redisCommand
*cmd
= lookupCommand(argv
[1]);
278 err
= "No such command in rename-command";
282 /* If the target command name is the emtpy string we just
283 * remove it from the command table. */
284 retval
= dictDelete(server
.commands
, argv
[1]);
285 redisAssert(retval
== DICT_OK
);
287 /* Otherwise we re-add the command under a different name. */
288 if (sdslen(argv
[2]) != 0) {
289 sds copy
= sdsdup(argv
[2]);
291 retval
= dictAdd(server
.commands
, copy
, cmd
);
292 if (retval
!= DICT_OK
) {
294 err
= "Target command name already exists"; goto loaderr
;
297 } else if (!strcasecmp(argv
[0],"cluster-enabled") && argc
== 2) {
298 if ((server
.cluster_enabled
= yesnotoi(argv
[1])) == -1) {
299 err
= "argument must be 'yes' or 'no'"; goto loaderr
;
301 } else if (!strcasecmp(argv
[0],"cluster-config-file") && argc
== 2) {
302 zfree(server
.cluster
.configfile
);
303 server
.cluster
.configfile
= zstrdup(argv
[1]);
304 } else if (!strcasecmp(argv
[0],"lua-time-limit") && argc
== 2) {
305 server
.lua_time_limit
= strtoll(argv
[1],NULL
,10);
306 } else if (!strcasecmp(argv
[0],"slowlog-log-slower-than") &&
309 server
.slowlog_log_slower_than
= strtoll(argv
[1],NULL
,10);
310 } else if (!strcasecmp(argv
[0],"slowlog-max-len") && argc
== 2) {
311 server
.slowlog_max_len
= strtoll(argv
[1],NULL
,10);
313 err
= "Bad directive or wrong number of arguments"; goto loaderr
;
315 for (j
= 0; j
< argc
; j
++)
320 if (fp
!= stdin
) fclose(fp
);
324 fprintf(stderr
, "\n*** FATAL CONFIG FILE ERROR ***\n");
325 fprintf(stderr
, "Reading the configuration file, at line %d\n", linenum
);
326 fprintf(stderr
, ">>> '%s'\n", line
);
327 fprintf(stderr
, "%s\n", err
);
331 /*-----------------------------------------------------------------------------
332 * CONFIG command for remote configuration
333 *----------------------------------------------------------------------------*/
335 void configSetCommand(redisClient
*c
) {
338 redisAssertWithInfo(c
,c
->argv
[2],c
->argv
[2]->encoding
== REDIS_ENCODING_RAW
);
339 redisAssertWithInfo(c
,c
->argv
[2],c
->argv
[3]->encoding
== REDIS_ENCODING_RAW
);
342 if (!strcasecmp(c
->argv
[2]->ptr
,"dbfilename")) {
343 zfree(server
.dbfilename
);
344 server
.dbfilename
= zstrdup(o
->ptr
);
345 } else if (!strcasecmp(c
->argv
[2]->ptr
,"requirepass")) {
346 zfree(server
.requirepass
);
347 server
.requirepass
= zstrdup(o
->ptr
);
348 } else if (!strcasecmp(c
->argv
[2]->ptr
,"masterauth")) {
349 zfree(server
.masterauth
);
350 server
.masterauth
= zstrdup(o
->ptr
);
351 } else if (!strcasecmp(c
->argv
[2]->ptr
,"maxmemory")) {
352 if (getLongLongFromObject(o
,&ll
) == REDIS_ERR
||
354 server
.maxmemory
= ll
;
355 if (server
.maxmemory
) freeMemoryIfNeeded();
356 } else if (!strcasecmp(c
->argv
[2]->ptr
,"maxmemory-policy")) {
357 if (!strcasecmp(o
->ptr
,"volatile-lru")) {
358 server
.maxmemory_policy
= REDIS_MAXMEMORY_VOLATILE_LRU
;
359 } else if (!strcasecmp(o
->ptr
,"volatile-random")) {
360 server
.maxmemory_policy
= REDIS_MAXMEMORY_VOLATILE_RANDOM
;
361 } else if (!strcasecmp(o
->ptr
,"volatile-ttl")) {
362 server
.maxmemory_policy
= REDIS_MAXMEMORY_VOLATILE_TTL
;
363 } else if (!strcasecmp(o
->ptr
,"allkeys-lru")) {
364 server
.maxmemory_policy
= REDIS_MAXMEMORY_ALLKEYS_LRU
;
365 } else if (!strcasecmp(o
->ptr
,"allkeys-random")) {
366 server
.maxmemory_policy
= REDIS_MAXMEMORY_ALLKEYS_RANDOM
;
367 } else if (!strcasecmp(o
->ptr
,"noeviction")) {
368 server
.maxmemory_policy
= REDIS_MAXMEMORY_NO_EVICTION
;
372 } else if (!strcasecmp(c
->argv
[2]->ptr
,"maxmemory-samples")) {
373 if (getLongLongFromObject(o
,&ll
) == REDIS_ERR
||
374 ll
<= 0) goto badfmt
;
375 server
.maxmemory_samples
= ll
;
376 } else if (!strcasecmp(c
->argv
[2]->ptr
,"timeout")) {
377 if (getLongLongFromObject(o
,&ll
) == REDIS_ERR
||
378 ll
< 0 || ll
> LONG_MAX
) goto badfmt
;
379 server
.maxidletime
= ll
;
380 } else if (!strcasecmp(c
->argv
[2]->ptr
,"appendfsync")) {
381 if (!strcasecmp(o
->ptr
,"no")) {
382 server
.appendfsync
= APPENDFSYNC_NO
;
383 } else if (!strcasecmp(o
->ptr
,"everysec")) {
384 server
.appendfsync
= APPENDFSYNC_EVERYSEC
;
385 } else if (!strcasecmp(o
->ptr
,"always")) {
386 server
.appendfsync
= APPENDFSYNC_ALWAYS
;
390 } else if (!strcasecmp(c
->argv
[2]->ptr
,"no-appendfsync-on-rewrite")) {
391 int yn
= yesnotoi(o
->ptr
);
393 if (yn
== -1) goto badfmt
;
394 server
.no_appendfsync_on_rewrite
= yn
;
395 } else if (!strcasecmp(c
->argv
[2]->ptr
,"appendonly")) {
396 int old
= server
.appendonly
;
397 int new = yesnotoi(o
->ptr
);
399 if (new == -1) goto badfmt
;
404 if (startAppendOnly() == REDIS_ERR
) {
406 "Unable to turn on AOF. Check server logs.");
411 } else if (!strcasecmp(c
->argv
[2]->ptr
,"auto-aof-rewrite-percentage")) {
412 if (getLongLongFromObject(o
,&ll
) == REDIS_ERR
|| ll
< 0) goto badfmt
;
413 server
.auto_aofrewrite_perc
= ll
;
414 } else if (!strcasecmp(c
->argv
[2]->ptr
,"auto-aof-rewrite-min-size")) {
415 if (getLongLongFromObject(o
,&ll
) == REDIS_ERR
|| ll
< 0) goto badfmt
;
416 server
.auto_aofrewrite_min_size
= ll
;
417 } else if (!strcasecmp(c
->argv
[2]->ptr
,"save")) {
419 sds
*v
= sdssplitlen(o
->ptr
,sdslen(o
->ptr
)," ",1,&vlen
);
421 /* Perform sanity check before setting the new config:
422 * - Even number of args
423 * - Seconds >= 1, changes >= 0 */
425 sdsfreesplitres(v
,vlen
);
428 for (j
= 0; j
< vlen
; j
++) {
432 val
= strtoll(v
[j
], &eptr
, 10);
433 if (eptr
[0] != '\0' ||
434 ((j
& 1) == 0 && val
< 1) ||
435 ((j
& 1) == 1 && val
< 0)) {
436 sdsfreesplitres(v
,vlen
);
440 /* Finally set the new config */
441 resetServerSaveParams();
442 for (j
= 0; j
< vlen
; j
+= 2) {
446 seconds
= strtoll(v
[j
],NULL
,10);
447 changes
= strtoll(v
[j
+1],NULL
,10);
448 appendServerSaveParams(seconds
, changes
);
450 sdsfreesplitres(v
,vlen
);
451 } else if (!strcasecmp(c
->argv
[2]->ptr
,"slave-serve-stale-data")) {
452 int yn
= yesnotoi(o
->ptr
);
454 if (yn
== -1) goto badfmt
;
455 server
.repl_serve_stale_data
= yn
;
456 } else if (!strcasecmp(c
->argv
[2]->ptr
,"dir")) {
457 if (chdir((char*)o
->ptr
) == -1) {
458 addReplyErrorFormat(c
,"Changing directory: %s", strerror(errno
));
461 } else if (!strcasecmp(c
->argv
[2]->ptr
,"hash-max-zipmap-entries")) {
462 if (getLongLongFromObject(o
,&ll
) == REDIS_ERR
|| ll
< 0) goto badfmt
;
463 server
.hash_max_zipmap_entries
= ll
;
464 } else if (!strcasecmp(c
->argv
[2]->ptr
,"hash-max-zipmap-value")) {
465 if (getLongLongFromObject(o
,&ll
) == REDIS_ERR
|| ll
< 0) goto badfmt
;
466 server
.hash_max_zipmap_value
= ll
;
467 } else if (!strcasecmp(c
->argv
[2]->ptr
,"list-max-ziplist-entries")) {
468 if (getLongLongFromObject(o
,&ll
) == REDIS_ERR
|| ll
< 0) goto badfmt
;
469 server
.list_max_ziplist_entries
= ll
;
470 } else if (!strcasecmp(c
->argv
[2]->ptr
,"list-max-ziplist-value")) {
471 if (getLongLongFromObject(o
,&ll
) == REDIS_ERR
|| ll
< 0) goto badfmt
;
472 server
.list_max_ziplist_value
= ll
;
473 } else if (!strcasecmp(c
->argv
[2]->ptr
,"set-max-intset-entries")) {
474 if (getLongLongFromObject(o
,&ll
) == REDIS_ERR
|| ll
< 0) goto badfmt
;
475 server
.set_max_intset_entries
= ll
;
476 } else if (!strcasecmp(c
->argv
[2]->ptr
,"zset-max-ziplist-entries")) {
477 if (getLongLongFromObject(o
,&ll
) == REDIS_ERR
|| ll
< 0) goto badfmt
;
478 server
.zset_max_ziplist_entries
= ll
;
479 } else if (!strcasecmp(c
->argv
[2]->ptr
,"zset-max-ziplist-value")) {
480 if (getLongLongFromObject(o
,&ll
) == REDIS_ERR
|| ll
< 0) goto badfmt
;
481 server
.zset_max_ziplist_value
= ll
;
482 } else if (!strcasecmp(c
->argv
[2]->ptr
,"lua-time-limit")) {
483 if (getLongLongFromObject(o
,&ll
) == REDIS_ERR
|| ll
< 0) goto badfmt
;
484 server
.lua_time_limit
= ll
;
485 } else if (!strcasecmp(c
->argv
[2]->ptr
,"slowlog-log-slower-than")) {
486 if (getLongLongFromObject(o
,&ll
) == REDIS_ERR
) goto badfmt
;
487 server
.slowlog_log_slower_than
= ll
;
488 } else if (!strcasecmp(c
->argv
[2]->ptr
,"slowlog-max-len")) {
489 if (getLongLongFromObject(o
,&ll
) == REDIS_ERR
|| ll
< 0) goto badfmt
;
490 server
.slowlog_max_len
= (unsigned)ll
;
491 } else if (!strcasecmp(c
->argv
[2]->ptr
,"loglevel")) {
492 if (!strcasecmp(o
->ptr
,"warning")) {
493 server
.verbosity
= REDIS_WARNING
;
494 } else if (!strcasecmp(o
->ptr
,"notice")) {
495 server
.verbosity
= REDIS_NOTICE
;
496 } else if (!strcasecmp(o
->ptr
,"verbose")) {
497 server
.verbosity
= REDIS_VERBOSE
;
498 } else if (!strcasecmp(o
->ptr
,"debug")) {
499 server
.verbosity
= REDIS_DEBUG
;
504 addReplyErrorFormat(c
,"Unsupported CONFIG parameter: %s",
505 (char*)c
->argv
[2]->ptr
);
508 addReply(c
,shared
.ok
);
511 badfmt
: /* Bad format errors */
512 addReplyErrorFormat(c
,"Invalid argument '%s' for CONFIG SET '%s'",
514 (char*)c
->argv
[2]->ptr
);
517 void configGetCommand(redisClient
*c
) {
518 robj
*o
= c
->argv
[2];
519 void *replylen
= addDeferredMultiBulkLength(c
);
520 char *pattern
= o
->ptr
;
523 redisAssertWithInfo(c
,o
,o
->encoding
== REDIS_ENCODING_RAW
);
525 if (stringmatch(pattern
,"dir",0)) {
528 if (getcwd(buf
,sizeof(buf
)) == NULL
)
531 addReplyBulkCString(c
,"dir");
532 addReplyBulkCString(c
,buf
);
535 if (stringmatch(pattern
,"dbfilename",0)) {
536 addReplyBulkCString(c
,"dbfilename");
537 addReplyBulkCString(c
,server
.dbfilename
);
540 if (stringmatch(pattern
,"requirepass",0)) {
541 addReplyBulkCString(c
,"requirepass");
542 addReplyBulkCString(c
,server
.requirepass
);
545 if (stringmatch(pattern
,"masterauth",0)) {
546 addReplyBulkCString(c
,"masterauth");
547 addReplyBulkCString(c
,server
.masterauth
);
550 if (stringmatch(pattern
,"maxmemory",0)) {
551 ll2string(buf
,sizeof(buf
),server
.maxmemory
);
552 addReplyBulkCString(c
,"maxmemory");
553 addReplyBulkCString(c
,buf
);
556 if (stringmatch(pattern
,"maxmemory-policy",0)) {
559 switch(server
.maxmemory_policy
) {
560 case REDIS_MAXMEMORY_VOLATILE_LRU
: s
= "volatile-lru"; break;
561 case REDIS_MAXMEMORY_VOLATILE_TTL
: s
= "volatile-ttl"; break;
562 case REDIS_MAXMEMORY_VOLATILE_RANDOM
: s
= "volatile-random"; break;
563 case REDIS_MAXMEMORY_ALLKEYS_LRU
: s
= "allkeys-lru"; break;
564 case REDIS_MAXMEMORY_ALLKEYS_RANDOM
: s
= "allkeys-random"; break;
565 case REDIS_MAXMEMORY_NO_EVICTION
: s
= "noeviction"; break;
566 default: s
= "unknown"; break; /* too harmless to panic */
568 addReplyBulkCString(c
,"maxmemory-policy");
569 addReplyBulkCString(c
,s
);
572 if (stringmatch(pattern
,"maxmemory-samples",0)) {
573 ll2string(buf
,sizeof(buf
),server
.maxmemory_samples
);
574 addReplyBulkCString(c
,"maxmemory-samples");
575 addReplyBulkCString(c
,buf
);
578 if (stringmatch(pattern
,"timeout",0)) {
579 ll2string(buf
,sizeof(buf
),server
.maxidletime
);
580 addReplyBulkCString(c
,"timeout");
581 addReplyBulkCString(c
,buf
);
584 if (stringmatch(pattern
,"appendonly",0)) {
585 addReplyBulkCString(c
,"appendonly");
586 addReplyBulkCString(c
,server
.appendonly
? "yes" : "no");
589 if (stringmatch(pattern
,"no-appendfsync-on-rewrite",0)) {
590 addReplyBulkCString(c
,"no-appendfsync-on-rewrite");
591 addReplyBulkCString(c
,server
.no_appendfsync_on_rewrite
? "yes" : "no");
594 if (stringmatch(pattern
,"appendfsync",0)) {
597 switch(server
.appendfsync
) {
598 case APPENDFSYNC_NO
: policy
= "no"; break;
599 case APPENDFSYNC_EVERYSEC
: policy
= "everysec"; break;
600 case APPENDFSYNC_ALWAYS
: policy
= "always"; break;
601 default: policy
= "unknown"; break; /* too harmless to panic */
603 addReplyBulkCString(c
,"appendfsync");
604 addReplyBulkCString(c
,policy
);
607 if (stringmatch(pattern
,"save",0)) {
608 sds buf
= sdsempty();
611 for (j
= 0; j
< server
.saveparamslen
; j
++) {
612 buf
= sdscatprintf(buf
,"%ld %d",
613 server
.saveparams
[j
].seconds
,
614 server
.saveparams
[j
].changes
);
615 if (j
!= server
.saveparamslen
-1)
616 buf
= sdscatlen(buf
," ",1);
618 addReplyBulkCString(c
,"save");
619 addReplyBulkCString(c
,buf
);
623 if (stringmatch(pattern
,"auto-aof-rewrite-percentage",0)) {
624 addReplyBulkCString(c
,"auto-aof-rewrite-percentage");
625 addReplyBulkLongLong(c
,server
.auto_aofrewrite_perc
);
628 if (stringmatch(pattern
,"auto-aof-rewrite-min-size",0)) {
629 addReplyBulkCString(c
,"auto-aof-rewrite-min-size");
630 addReplyBulkLongLong(c
,server
.auto_aofrewrite_min_size
);
633 if (stringmatch(pattern
,"slave-serve-stale-data",0)) {
634 addReplyBulkCString(c
,"slave-serve-stale-data");
635 addReplyBulkCString(c
,server
.repl_serve_stale_data
? "yes" : "no");
638 if (stringmatch(pattern
,"hash-max-zipmap-entries",0)) {
639 addReplyBulkCString(c
,"hash-max-zipmap-entries");
640 addReplyBulkLongLong(c
,server
.hash_max_zipmap_entries
);
643 if (stringmatch(pattern
,"hash-max-zipmap-value",0)) {
644 addReplyBulkCString(c
,"hash-max-zipmap-value");
645 addReplyBulkLongLong(c
,server
.hash_max_zipmap_value
);
648 if (stringmatch(pattern
,"list-max-ziplist-entries",0)) {
649 addReplyBulkCString(c
,"list-max-ziplist-entries");
650 addReplyBulkLongLong(c
,server
.list_max_ziplist_entries
);
653 if (stringmatch(pattern
,"list-max-ziplist-value",0)) {
654 addReplyBulkCString(c
,"list-max-ziplist-value");
655 addReplyBulkLongLong(c
,server
.list_max_ziplist_value
);
658 if (stringmatch(pattern
,"set-max-intset-entries",0)) {
659 addReplyBulkCString(c
,"set-max-intset-entries");
660 addReplyBulkLongLong(c
,server
.set_max_intset_entries
);
663 if (stringmatch(pattern
,"zset-max-ziplist-entries",0)) {
664 addReplyBulkCString(c
,"zset-max-ziplist-entries");
665 addReplyBulkLongLong(c
,server
.zset_max_ziplist_entries
);
668 if (stringmatch(pattern
,"zset-max-ziplist-value",0)) {
669 addReplyBulkCString(c
,"zset-max-ziplist-value");
670 addReplyBulkLongLong(c
,server
.zset_max_ziplist_value
);
673 if (stringmatch(pattern
,"lua-time-limit",0)) {
674 addReplyBulkCString(c
,"lua-time-limit");
675 addReplyBulkLongLong(c
,server
.lua_time_limit
);
678 if (stringmatch(pattern
,"slowlog-log-slower-than",0)) {
679 addReplyBulkCString(c
,"slowlog-log-slower-than");
680 addReplyBulkLongLong(c
,server
.slowlog_log_slower_than
);
683 if (stringmatch(pattern
,"slowlog-max-len",0)) {
684 addReplyBulkCString(c
,"slowlog-max-len");
685 addReplyBulkLongLong(c
,server
.slowlog_max_len
);
688 if (stringmatch(pattern
,"loglevel",0)) {
691 switch(server
.verbosity
) {
692 case REDIS_WARNING
: s
= "warning"; break;
693 case REDIS_VERBOSE
: s
= "verbose"; break;
694 case REDIS_NOTICE
: s
= "notice"; break;
695 case REDIS_DEBUG
: s
= "debug"; break;
696 default: s
= "unknown"; break; /* too harmless to panic */
698 addReplyBulkCString(c
,"loglevel");
699 addReplyBulkCString(c
,s
);
702 setDeferredMultiBulkLength(c
,replylen
,matches
*2);
705 void configCommand(redisClient
*c
) {
706 if (!strcasecmp(c
->argv
[1]->ptr
,"set")) {
707 if (c
->argc
!= 4) goto badarity
;
709 } else if (!strcasecmp(c
->argv
[1]->ptr
,"get")) {
710 if (c
->argc
!= 3) goto badarity
;
712 } else if (!strcasecmp(c
->argv
[1]->ptr
,"resetstat")) {
713 if (c
->argc
!= 2) goto badarity
;
714 server
.stat_keyspace_hits
= 0;
715 server
.stat_keyspace_misses
= 0;
716 server
.stat_numcommands
= 0;
717 server
.stat_numconnections
= 0;
718 server
.stat_expiredkeys
= 0;
719 resetCommandTableStats();
720 addReply(c
,shared
.ok
);
723 "CONFIG subcommand must be one of GET, SET, RESETSTAT");
728 addReplyErrorFormat(c
,"Wrong number of arguments for CONFIG %s",
729 (char*) c
->argv
[1]->ptr
);