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) {
78 server
.unixsocketperm
= (mode_t
)strtol(argv
[1], NULL
, 8);
79 if (errno
|| server
.unixsocketperm
> 0777) {
80 err
= "Invalid socket file permissions"; goto loaderr
;
82 } else if (!strcasecmp(argv
[0],"save") && argc
== 3) {
83 int seconds
= atoi(argv
[1]);
84 int changes
= atoi(argv
[2]);
85 if (seconds
< 1 || changes
< 0) {
86 err
= "Invalid save parameters"; goto loaderr
;
88 appendServerSaveParams(seconds
,changes
);
89 } else if (!strcasecmp(argv
[0],"dir") && argc
== 2) {
90 if (chdir(argv
[1]) == -1) {
91 redisLog(REDIS_WARNING
,"Can't chdir to '%s': %s",
92 argv
[1], strerror(errno
));
95 } else if (!strcasecmp(argv
[0],"loglevel") && argc
== 2) {
96 if (!strcasecmp(argv
[1],"debug")) server
.verbosity
= REDIS_DEBUG
;
97 else if (!strcasecmp(argv
[1],"verbose")) server
.verbosity
= REDIS_VERBOSE
;
98 else if (!strcasecmp(argv
[1],"notice")) server
.verbosity
= REDIS_NOTICE
;
99 else if (!strcasecmp(argv
[1],"warning")) server
.verbosity
= REDIS_WARNING
;
101 err
= "Invalid log level. Must be one of debug, notice, warning";
104 } else if (!strcasecmp(argv
[0],"logfile") && argc
== 2) {
107 server
.logfile
= zstrdup(argv
[1]);
108 if (!strcasecmp(server
.logfile
,"stdout")) {
109 zfree(server
.logfile
);
110 server
.logfile
= NULL
;
112 if (server
.logfile
) {
113 /* Test if we are able to open the file. The server will not
114 * be able to abort just for this problem later... */
115 logfp
= fopen(server
.logfile
,"a");
117 err
= sdscatprintf(sdsempty(),
118 "Can't open the log file: %s", strerror(errno
));
123 } else if (!strcasecmp(argv
[0],"syslog-enabled") && argc
== 2) {
124 if ((server
.syslog_enabled
= yesnotoi(argv
[1])) == -1) {
125 err
= "argument must be 'yes' or 'no'"; goto loaderr
;
127 } else if (!strcasecmp(argv
[0],"syslog-ident") && argc
== 2) {
128 if (server
.syslog_ident
) zfree(server
.syslog_ident
);
129 server
.syslog_ident
= zstrdup(argv
[1]);
130 } else if (!strcasecmp(argv
[0],"syslog-facility") && argc
== 2) {
134 } validSyslogFacilities
[] = {
136 {"local0", LOG_LOCAL0
},
137 {"local1", LOG_LOCAL1
},
138 {"local2", LOG_LOCAL2
},
139 {"local3", LOG_LOCAL3
},
140 {"local4", LOG_LOCAL4
},
141 {"local5", LOG_LOCAL5
},
142 {"local6", LOG_LOCAL6
},
143 {"local7", LOG_LOCAL7
},
148 for (i
= 0; validSyslogFacilities
[i
].name
; i
++) {
149 if (!strcasecmp(validSyslogFacilities
[i
].name
, argv
[1])) {
150 server
.syslog_facility
= validSyslogFacilities
[i
].value
;
155 if (!validSyslogFacilities
[i
].name
) {
156 err
= "Invalid log facility. Must be one of USER or between LOCAL0-LOCAL7";
159 } else if (!strcasecmp(argv
[0],"databases") && argc
== 2) {
160 server
.dbnum
= atoi(argv
[1]);
161 if (server
.dbnum
< 1) {
162 err
= "Invalid number of databases"; goto loaderr
;
164 } else if (!strcasecmp(argv
[0],"include") && argc
== 2) {
165 loadServerConfig(argv
[1]);
166 } else if (!strcasecmp(argv
[0],"maxclients") && argc
== 2) {
167 server
.maxclients
= atoi(argv
[1]);
168 } else if (!strcasecmp(argv
[0],"maxmemory") && argc
== 2) {
169 server
.maxmemory
= memtoll(argv
[1],NULL
);
170 } else if (!strcasecmp(argv
[0],"maxmemory-policy") && argc
== 2) {
171 if (!strcasecmp(argv
[1],"volatile-lru")) {
172 server
.maxmemory_policy
= REDIS_MAXMEMORY_VOLATILE_LRU
;
173 } else if (!strcasecmp(argv
[1],"volatile-random")) {
174 server
.maxmemory_policy
= REDIS_MAXMEMORY_VOLATILE_RANDOM
;
175 } else if (!strcasecmp(argv
[1],"volatile-ttl")) {
176 server
.maxmemory_policy
= REDIS_MAXMEMORY_VOLATILE_TTL
;
177 } else if (!strcasecmp(argv
[1],"allkeys-lru")) {
178 server
.maxmemory_policy
= REDIS_MAXMEMORY_ALLKEYS_LRU
;
179 } else if (!strcasecmp(argv
[1],"allkeys-random")) {
180 server
.maxmemory_policy
= REDIS_MAXMEMORY_ALLKEYS_RANDOM
;
181 } else if (!strcasecmp(argv
[1],"noeviction")) {
182 server
.maxmemory_policy
= REDIS_MAXMEMORY_NO_EVICTION
;
184 err
= "Invalid maxmemory policy";
187 } else if (!strcasecmp(argv
[0],"maxmemory-samples") && argc
== 2) {
188 server
.maxmemory_samples
= atoi(argv
[1]);
189 if (server
.maxmemory_samples
<= 0) {
190 err
= "maxmemory-samples must be 1 or greater";
193 } else if (!strcasecmp(argv
[0],"slaveof") && argc
== 3) {
194 server
.masterhost
= sdsnew(argv
[1]);
195 server
.masterport
= atoi(argv
[2]);
196 server
.replstate
= REDIS_REPL_CONNECT
;
197 } else if (!strcasecmp(argv
[0],"repl-ping-slave-period") && argc
== 2) {
198 server
.repl_ping_slave_period
= atoi(argv
[1]);
199 if (server
.repl_ping_slave_period
<= 0) {
200 err
= "repl-ping-slave-period must be 1 or greater";
203 } else if (!strcasecmp(argv
[0],"repl-timeout") && argc
== 2) {
204 server
.repl_timeout
= atoi(argv
[1]);
205 if (server
.repl_timeout
<= 0) {
206 err
= "repl-timeout must be 1 or greater";
209 } else if (!strcasecmp(argv
[0],"masterauth") && argc
== 2) {
210 server
.masterauth
= zstrdup(argv
[1]);
211 } else if (!strcasecmp(argv
[0],"slave-serve-stale-data") && argc
== 2) {
212 if ((server
.repl_serve_stale_data
= yesnotoi(argv
[1])) == -1) {
213 err
= "argument must be 'yes' or 'no'"; goto loaderr
;
215 } else if (!strcasecmp(argv
[0],"glueoutputbuf")) {
216 redisLog(REDIS_WARNING
, "Deprecated configuration directive: \"%s\"", argv
[0]);
217 } else if (!strcasecmp(argv
[0],"rdbcompression") && argc
== 2) {
218 if ((server
.rdbcompression
= yesnotoi(argv
[1])) == -1) {
219 err
= "argument must be 'yes' or 'no'"; goto loaderr
;
221 } else if (!strcasecmp(argv
[0],"activerehashing") && argc
== 2) {
222 if ((server
.activerehashing
= yesnotoi(argv
[1])) == -1) {
223 err
= "argument must be 'yes' or 'no'"; goto loaderr
;
225 } else if (!strcasecmp(argv
[0],"daemonize") && argc
== 2) {
226 if ((server
.daemonize
= yesnotoi(argv
[1])) == -1) {
227 err
= "argument must be 'yes' or 'no'"; goto loaderr
;
229 } else if (!strcasecmp(argv
[0],"appendonly") && argc
== 2) {
230 if ((server
.appendonly
= yesnotoi(argv
[1])) == -1) {
231 err
= "argument must be 'yes' or 'no'"; goto loaderr
;
233 } else if (!strcasecmp(argv
[0],"appendfilename") && argc
== 2) {
234 zfree(server
.appendfilename
);
235 server
.appendfilename
= zstrdup(argv
[1]);
236 } else if (!strcasecmp(argv
[0],"no-appendfsync-on-rewrite")
238 if ((server
.no_appendfsync_on_rewrite
= yesnotoi(argv
[1])) == -1) {
239 err
= "argument must be 'yes' or 'no'"; goto loaderr
;
241 } else if (!strcasecmp(argv
[0],"appendfsync") && argc
== 2) {
242 if (!strcasecmp(argv
[1],"no")) {
243 server
.appendfsync
= APPENDFSYNC_NO
;
244 } else if (!strcasecmp(argv
[1],"always")) {
245 server
.appendfsync
= APPENDFSYNC_ALWAYS
;
246 } else if (!strcasecmp(argv
[1],"everysec")) {
247 server
.appendfsync
= APPENDFSYNC_EVERYSEC
;
249 err
= "argument must be 'no', 'always' or 'everysec'";
252 } else if (!strcasecmp(argv
[0],"auto-aof-rewrite-percentage") &&
255 server
.auto_aofrewrite_perc
= atoi(argv
[1]);
256 if (server
.auto_aofrewrite_perc
< 0) {
257 err
= "Invalid negative percentage for AOF auto rewrite";
260 } else if (!strcasecmp(argv
[0],"auto-aof-rewrite-min-size") &&
263 server
.auto_aofrewrite_min_size
= memtoll(argv
[1],NULL
);
264 } else if (!strcasecmp(argv
[0],"requirepass") && argc
== 2) {
265 server
.requirepass
= zstrdup(argv
[1]);
266 } else if (!strcasecmp(argv
[0],"pidfile") && argc
== 2) {
267 zfree(server
.pidfile
);
268 server
.pidfile
= zstrdup(argv
[1]);
269 } else if (!strcasecmp(argv
[0],"dbfilename") && argc
== 2) {
270 zfree(server
.dbfilename
);
271 server
.dbfilename
= zstrdup(argv
[1]);
272 } else if (!strcasecmp(argv
[0],"hash-max-zipmap-entries") && argc
== 2) {
273 server
.hash_max_zipmap_entries
= memtoll(argv
[1], NULL
);
274 } else if (!strcasecmp(argv
[0],"hash-max-zipmap-value") && argc
== 2) {
275 server
.hash_max_zipmap_value
= memtoll(argv
[1], NULL
);
276 } else if (!strcasecmp(argv
[0],"list-max-ziplist-entries") && argc
== 2){
277 server
.list_max_ziplist_entries
= memtoll(argv
[1], NULL
);
278 } else if (!strcasecmp(argv
[0],"list-max-ziplist-value") && argc
== 2) {
279 server
.list_max_ziplist_value
= memtoll(argv
[1], NULL
);
280 } else if (!strcasecmp(argv
[0],"set-max-intset-entries") && argc
== 2) {
281 server
.set_max_intset_entries
= memtoll(argv
[1], NULL
);
282 } else if (!strcasecmp(argv
[0],"zset-max-ziplist-entries") && argc
== 2) {
283 server
.zset_max_ziplist_entries
= memtoll(argv
[1], NULL
);
284 } else if (!strcasecmp(argv
[0],"zset-max-ziplist-value") && argc
== 2) {
285 server
.zset_max_ziplist_value
= memtoll(argv
[1], NULL
);
286 } else if (!strcasecmp(argv
[0],"rename-command") && argc
== 3) {
287 struct redisCommand
*cmd
= lookupCommand(argv
[1]);
291 err
= "No such command in rename-command";
295 /* If the target command name is the emtpy string we just
296 * remove it from the command table. */
297 retval
= dictDelete(server
.commands
, argv
[1]);
298 redisAssert(retval
== DICT_OK
);
300 /* Otherwise we re-add the command under a different name. */
301 if (sdslen(argv
[2]) != 0) {
302 sds copy
= sdsdup(argv
[2]);
304 retval
= dictAdd(server
.commands
, copy
, cmd
);
305 if (retval
!= DICT_OK
) {
307 err
= "Target command name already exists"; goto loaderr
;
310 } else if (!strcasecmp(argv
[0],"cluster-enabled") && argc
== 2) {
311 if ((server
.cluster_enabled
= yesnotoi(argv
[1])) == -1) {
312 err
= "argument must be 'yes' or 'no'"; goto loaderr
;
314 } else if (!strcasecmp(argv
[0],"cluster-config-file") && argc
== 2) {
315 zfree(server
.cluster
.configfile
);
316 server
.cluster
.configfile
= zstrdup(argv
[1]);
317 } else if (!strcasecmp(argv
[0],"lua-time-limit") && argc
== 2) {
318 server
.lua_time_limit
= strtoll(argv
[1],NULL
,10);
319 } else if (!strcasecmp(argv
[0],"slowlog-log-slower-than") &&
322 server
.slowlog_log_slower_than
= strtoll(argv
[1],NULL
,10);
323 } else if (!strcasecmp(argv
[0],"slowlog-max-len") && argc
== 2) {
324 server
.slowlog_max_len
= strtoll(argv
[1],NULL
,10);
326 err
= "Bad directive or wrong number of arguments"; goto loaderr
;
328 for (j
= 0; j
< argc
; j
++)
333 if (fp
!= stdin
) fclose(fp
);
337 fprintf(stderr
, "\n*** FATAL CONFIG FILE ERROR ***\n");
338 fprintf(stderr
, "Reading the configuration file, at line %d\n", linenum
);
339 fprintf(stderr
, ">>> '%s'\n", line
);
340 fprintf(stderr
, "%s\n", err
);
344 /*-----------------------------------------------------------------------------
345 * CONFIG command for remote configuration
346 *----------------------------------------------------------------------------*/
348 void configSetCommand(redisClient
*c
) {
351 redisAssertWithInfo(c
,c
->argv
[2],c
->argv
[2]->encoding
== REDIS_ENCODING_RAW
);
352 redisAssertWithInfo(c
,c
->argv
[2],c
->argv
[3]->encoding
== REDIS_ENCODING_RAW
);
355 if (!strcasecmp(c
->argv
[2]->ptr
,"dbfilename")) {
356 zfree(server
.dbfilename
);
357 server
.dbfilename
= zstrdup(o
->ptr
);
358 } else if (!strcasecmp(c
->argv
[2]->ptr
,"requirepass")) {
359 zfree(server
.requirepass
);
360 server
.requirepass
= ((char*)o
->ptr
)[0] ? zstrdup(o
->ptr
) : NULL
;
361 } else if (!strcasecmp(c
->argv
[2]->ptr
,"masterauth")) {
362 zfree(server
.masterauth
);
363 server
.masterauth
= zstrdup(o
->ptr
);
364 } else if (!strcasecmp(c
->argv
[2]->ptr
,"maxmemory")) {
365 if (getLongLongFromObject(o
,&ll
) == REDIS_ERR
||
367 server
.maxmemory
= ll
;
368 if (server
.maxmemory
) freeMemoryIfNeeded();
369 } else if (!strcasecmp(c
->argv
[2]->ptr
,"maxmemory-policy")) {
370 if (!strcasecmp(o
->ptr
,"volatile-lru")) {
371 server
.maxmemory_policy
= REDIS_MAXMEMORY_VOLATILE_LRU
;
372 } else if (!strcasecmp(o
->ptr
,"volatile-random")) {
373 server
.maxmemory_policy
= REDIS_MAXMEMORY_VOLATILE_RANDOM
;
374 } else if (!strcasecmp(o
->ptr
,"volatile-ttl")) {
375 server
.maxmemory_policy
= REDIS_MAXMEMORY_VOLATILE_TTL
;
376 } else if (!strcasecmp(o
->ptr
,"allkeys-lru")) {
377 server
.maxmemory_policy
= REDIS_MAXMEMORY_ALLKEYS_LRU
;
378 } else if (!strcasecmp(o
->ptr
,"allkeys-random")) {
379 server
.maxmemory_policy
= REDIS_MAXMEMORY_ALLKEYS_RANDOM
;
380 } else if (!strcasecmp(o
->ptr
,"noeviction")) {
381 server
.maxmemory_policy
= REDIS_MAXMEMORY_NO_EVICTION
;
385 } else if (!strcasecmp(c
->argv
[2]->ptr
,"maxmemory-samples")) {
386 if (getLongLongFromObject(o
,&ll
) == REDIS_ERR
||
387 ll
<= 0) goto badfmt
;
388 server
.maxmemory_samples
= ll
;
389 } else if (!strcasecmp(c
->argv
[2]->ptr
,"timeout")) {
390 if (getLongLongFromObject(o
,&ll
) == REDIS_ERR
||
391 ll
< 0 || ll
> LONG_MAX
) goto badfmt
;
392 server
.maxidletime
= ll
;
393 } else if (!strcasecmp(c
->argv
[2]->ptr
,"appendfsync")) {
394 if (!strcasecmp(o
->ptr
,"no")) {
395 server
.appendfsync
= APPENDFSYNC_NO
;
396 } else if (!strcasecmp(o
->ptr
,"everysec")) {
397 server
.appendfsync
= APPENDFSYNC_EVERYSEC
;
398 } else if (!strcasecmp(o
->ptr
,"always")) {
399 server
.appendfsync
= APPENDFSYNC_ALWAYS
;
403 } else if (!strcasecmp(c
->argv
[2]->ptr
,"no-appendfsync-on-rewrite")) {
404 int yn
= yesnotoi(o
->ptr
);
406 if (yn
== -1) goto badfmt
;
407 server
.no_appendfsync_on_rewrite
= yn
;
408 } else if (!strcasecmp(c
->argv
[2]->ptr
,"appendonly")) {
409 int old
= server
.appendonly
;
410 int new = yesnotoi(o
->ptr
);
412 if (new == -1) goto badfmt
;
417 if (startAppendOnly() == REDIS_ERR
) {
419 "Unable to turn on AOF. Check server logs.");
424 } else if (!strcasecmp(c
->argv
[2]->ptr
,"auto-aof-rewrite-percentage")) {
425 if (getLongLongFromObject(o
,&ll
) == REDIS_ERR
|| ll
< 0) goto badfmt
;
426 server
.auto_aofrewrite_perc
= ll
;
427 } else if (!strcasecmp(c
->argv
[2]->ptr
,"auto-aof-rewrite-min-size")) {
428 if (getLongLongFromObject(o
,&ll
) == REDIS_ERR
|| ll
< 0) goto badfmt
;
429 server
.auto_aofrewrite_min_size
= ll
;
430 } else if (!strcasecmp(c
->argv
[2]->ptr
,"save")) {
432 sds
*v
= sdssplitlen(o
->ptr
,sdslen(o
->ptr
)," ",1,&vlen
);
434 /* Perform sanity check before setting the new config:
435 * - Even number of args
436 * - Seconds >= 1, changes >= 0 */
438 sdsfreesplitres(v
,vlen
);
441 for (j
= 0; j
< vlen
; j
++) {
445 val
= strtoll(v
[j
], &eptr
, 10);
446 if (eptr
[0] != '\0' ||
447 ((j
& 1) == 0 && val
< 1) ||
448 ((j
& 1) == 1 && val
< 0)) {
449 sdsfreesplitres(v
,vlen
);
453 /* Finally set the new config */
454 resetServerSaveParams();
455 for (j
= 0; j
< vlen
; j
+= 2) {
459 seconds
= strtoll(v
[j
],NULL
,10);
460 changes
= strtoll(v
[j
+1],NULL
,10);
461 appendServerSaveParams(seconds
, changes
);
463 sdsfreesplitres(v
,vlen
);
464 } else if (!strcasecmp(c
->argv
[2]->ptr
,"slave-serve-stale-data")) {
465 int yn
= yesnotoi(o
->ptr
);
467 if (yn
== -1) goto badfmt
;
468 server
.repl_serve_stale_data
= yn
;
469 } else if (!strcasecmp(c
->argv
[2]->ptr
,"dir")) {
470 if (chdir((char*)o
->ptr
) == -1) {
471 addReplyErrorFormat(c
,"Changing directory: %s", strerror(errno
));
474 } else if (!strcasecmp(c
->argv
[2]->ptr
,"hash-max-zipmap-entries")) {
475 if (getLongLongFromObject(o
,&ll
) == REDIS_ERR
|| ll
< 0) goto badfmt
;
476 server
.hash_max_zipmap_entries
= ll
;
477 } else if (!strcasecmp(c
->argv
[2]->ptr
,"hash-max-zipmap-value")) {
478 if (getLongLongFromObject(o
,&ll
) == REDIS_ERR
|| ll
< 0) goto badfmt
;
479 server
.hash_max_zipmap_value
= ll
;
480 } else if (!strcasecmp(c
->argv
[2]->ptr
,"list-max-ziplist-entries")) {
481 if (getLongLongFromObject(o
,&ll
) == REDIS_ERR
|| ll
< 0) goto badfmt
;
482 server
.list_max_ziplist_entries
= ll
;
483 } else if (!strcasecmp(c
->argv
[2]->ptr
,"list-max-ziplist-value")) {
484 if (getLongLongFromObject(o
,&ll
) == REDIS_ERR
|| ll
< 0) goto badfmt
;
485 server
.list_max_ziplist_value
= ll
;
486 } else if (!strcasecmp(c
->argv
[2]->ptr
,"set-max-intset-entries")) {
487 if (getLongLongFromObject(o
,&ll
) == REDIS_ERR
|| ll
< 0) goto badfmt
;
488 server
.set_max_intset_entries
= ll
;
489 } else if (!strcasecmp(c
->argv
[2]->ptr
,"zset-max-ziplist-entries")) {
490 if (getLongLongFromObject(o
,&ll
) == REDIS_ERR
|| ll
< 0) goto badfmt
;
491 server
.zset_max_ziplist_entries
= ll
;
492 } else if (!strcasecmp(c
->argv
[2]->ptr
,"zset-max-ziplist-value")) {
493 if (getLongLongFromObject(o
,&ll
) == REDIS_ERR
|| ll
< 0) goto badfmt
;
494 server
.zset_max_ziplist_value
= ll
;
495 } else if (!strcasecmp(c
->argv
[2]->ptr
,"lua-time-limit")) {
496 if (getLongLongFromObject(o
,&ll
) == REDIS_ERR
|| ll
< 0) goto badfmt
;
497 server
.lua_time_limit
= ll
;
498 } else if (!strcasecmp(c
->argv
[2]->ptr
,"slowlog-log-slower-than")) {
499 if (getLongLongFromObject(o
,&ll
) == REDIS_ERR
) goto badfmt
;
500 server
.slowlog_log_slower_than
= ll
;
501 } else if (!strcasecmp(c
->argv
[2]->ptr
,"slowlog-max-len")) {
502 if (getLongLongFromObject(o
,&ll
) == REDIS_ERR
|| ll
< 0) goto badfmt
;
503 server
.slowlog_max_len
= (unsigned)ll
;
504 } else if (!strcasecmp(c
->argv
[2]->ptr
,"loglevel")) {
505 if (!strcasecmp(o
->ptr
,"warning")) {
506 server
.verbosity
= REDIS_WARNING
;
507 } else if (!strcasecmp(o
->ptr
,"notice")) {
508 server
.verbosity
= REDIS_NOTICE
;
509 } else if (!strcasecmp(o
->ptr
,"verbose")) {
510 server
.verbosity
= REDIS_VERBOSE
;
511 } else if (!strcasecmp(o
->ptr
,"debug")) {
512 server
.verbosity
= REDIS_DEBUG
;
517 addReplyErrorFormat(c
,"Unsupported CONFIG parameter: %s",
518 (char*)c
->argv
[2]->ptr
);
521 addReply(c
,shared
.ok
);
524 badfmt
: /* Bad format errors */
525 addReplyErrorFormat(c
,"Invalid argument '%s' for CONFIG SET '%s'",
527 (char*)c
->argv
[2]->ptr
);
530 void configGetCommand(redisClient
*c
) {
531 robj
*o
= c
->argv
[2];
532 void *replylen
= addDeferredMultiBulkLength(c
);
533 char *pattern
= o
->ptr
;
536 redisAssertWithInfo(c
,o
,o
->encoding
== REDIS_ENCODING_RAW
);
538 if (stringmatch(pattern
,"dir",0)) {
541 if (getcwd(buf
,sizeof(buf
)) == NULL
)
544 addReplyBulkCString(c
,"dir");
545 addReplyBulkCString(c
,buf
);
548 if (stringmatch(pattern
,"dbfilename",0)) {
549 addReplyBulkCString(c
,"dbfilename");
550 addReplyBulkCString(c
,server
.dbfilename
);
553 if (stringmatch(pattern
,"requirepass",0)) {
554 addReplyBulkCString(c
,"requirepass");
555 addReplyBulkCString(c
,server
.requirepass
);
558 if (stringmatch(pattern
,"masterauth",0)) {
559 addReplyBulkCString(c
,"masterauth");
560 addReplyBulkCString(c
,server
.masterauth
);
563 if (stringmatch(pattern
,"maxmemory",0)) {
564 ll2string(buf
,sizeof(buf
),server
.maxmemory
);
565 addReplyBulkCString(c
,"maxmemory");
566 addReplyBulkCString(c
,buf
);
569 if (stringmatch(pattern
,"maxmemory-policy",0)) {
572 switch(server
.maxmemory_policy
) {
573 case REDIS_MAXMEMORY_VOLATILE_LRU
: s
= "volatile-lru"; break;
574 case REDIS_MAXMEMORY_VOLATILE_TTL
: s
= "volatile-ttl"; break;
575 case REDIS_MAXMEMORY_VOLATILE_RANDOM
: s
= "volatile-random"; break;
576 case REDIS_MAXMEMORY_ALLKEYS_LRU
: s
= "allkeys-lru"; break;
577 case REDIS_MAXMEMORY_ALLKEYS_RANDOM
: s
= "allkeys-random"; break;
578 case REDIS_MAXMEMORY_NO_EVICTION
: s
= "noeviction"; break;
579 default: s
= "unknown"; break; /* too harmless to panic */
581 addReplyBulkCString(c
,"maxmemory-policy");
582 addReplyBulkCString(c
,s
);
585 if (stringmatch(pattern
,"maxmemory-samples",0)) {
586 ll2string(buf
,sizeof(buf
),server
.maxmemory_samples
);
587 addReplyBulkCString(c
,"maxmemory-samples");
588 addReplyBulkCString(c
,buf
);
591 if (stringmatch(pattern
,"timeout",0)) {
592 ll2string(buf
,sizeof(buf
),server
.maxidletime
);
593 addReplyBulkCString(c
,"timeout");
594 addReplyBulkCString(c
,buf
);
597 if (stringmatch(pattern
,"appendonly",0)) {
598 addReplyBulkCString(c
,"appendonly");
599 addReplyBulkCString(c
,server
.appendonly
? "yes" : "no");
602 if (stringmatch(pattern
,"no-appendfsync-on-rewrite",0)) {
603 addReplyBulkCString(c
,"no-appendfsync-on-rewrite");
604 addReplyBulkCString(c
,server
.no_appendfsync_on_rewrite
? "yes" : "no");
607 if (stringmatch(pattern
,"appendfsync",0)) {
610 switch(server
.appendfsync
) {
611 case APPENDFSYNC_NO
: policy
= "no"; break;
612 case APPENDFSYNC_EVERYSEC
: policy
= "everysec"; break;
613 case APPENDFSYNC_ALWAYS
: policy
= "always"; break;
614 default: policy
= "unknown"; break; /* too harmless to panic */
616 addReplyBulkCString(c
,"appendfsync");
617 addReplyBulkCString(c
,policy
);
620 if (stringmatch(pattern
,"save",0)) {
621 sds buf
= sdsempty();
624 for (j
= 0; j
< server
.saveparamslen
; j
++) {
625 buf
= sdscatprintf(buf
,"%ld %d",
626 server
.saveparams
[j
].seconds
,
627 server
.saveparams
[j
].changes
);
628 if (j
!= server
.saveparamslen
-1)
629 buf
= sdscatlen(buf
," ",1);
631 addReplyBulkCString(c
,"save");
632 addReplyBulkCString(c
,buf
);
636 if (stringmatch(pattern
,"auto-aof-rewrite-percentage",0)) {
637 addReplyBulkCString(c
,"auto-aof-rewrite-percentage");
638 addReplyBulkLongLong(c
,server
.auto_aofrewrite_perc
);
641 if (stringmatch(pattern
,"auto-aof-rewrite-min-size",0)) {
642 addReplyBulkCString(c
,"auto-aof-rewrite-min-size");
643 addReplyBulkLongLong(c
,server
.auto_aofrewrite_min_size
);
646 if (stringmatch(pattern
,"slave-serve-stale-data",0)) {
647 addReplyBulkCString(c
,"slave-serve-stale-data");
648 addReplyBulkCString(c
,server
.repl_serve_stale_data
? "yes" : "no");
651 if (stringmatch(pattern
,"hash-max-zipmap-entries",0)) {
652 addReplyBulkCString(c
,"hash-max-zipmap-entries");
653 addReplyBulkLongLong(c
,server
.hash_max_zipmap_entries
);
656 if (stringmatch(pattern
,"hash-max-zipmap-value",0)) {
657 addReplyBulkCString(c
,"hash-max-zipmap-value");
658 addReplyBulkLongLong(c
,server
.hash_max_zipmap_value
);
661 if (stringmatch(pattern
,"list-max-ziplist-entries",0)) {
662 addReplyBulkCString(c
,"list-max-ziplist-entries");
663 addReplyBulkLongLong(c
,server
.list_max_ziplist_entries
);
666 if (stringmatch(pattern
,"list-max-ziplist-value",0)) {
667 addReplyBulkCString(c
,"list-max-ziplist-value");
668 addReplyBulkLongLong(c
,server
.list_max_ziplist_value
);
671 if (stringmatch(pattern
,"set-max-intset-entries",0)) {
672 addReplyBulkCString(c
,"set-max-intset-entries");
673 addReplyBulkLongLong(c
,server
.set_max_intset_entries
);
676 if (stringmatch(pattern
,"zset-max-ziplist-entries",0)) {
677 addReplyBulkCString(c
,"zset-max-ziplist-entries");
678 addReplyBulkLongLong(c
,server
.zset_max_ziplist_entries
);
681 if (stringmatch(pattern
,"zset-max-ziplist-value",0)) {
682 addReplyBulkCString(c
,"zset-max-ziplist-value");
683 addReplyBulkLongLong(c
,server
.zset_max_ziplist_value
);
686 if (stringmatch(pattern
,"lua-time-limit",0)) {
687 addReplyBulkCString(c
,"lua-time-limit");
688 addReplyBulkLongLong(c
,server
.lua_time_limit
);
691 if (stringmatch(pattern
,"slowlog-log-slower-than",0)) {
692 addReplyBulkCString(c
,"slowlog-log-slower-than");
693 addReplyBulkLongLong(c
,server
.slowlog_log_slower_than
);
696 if (stringmatch(pattern
,"slowlog-max-len",0)) {
697 addReplyBulkCString(c
,"slowlog-max-len");
698 addReplyBulkLongLong(c
,server
.slowlog_max_len
);
701 if (stringmatch(pattern
,"loglevel",0)) {
704 switch(server
.verbosity
) {
705 case REDIS_WARNING
: s
= "warning"; break;
706 case REDIS_VERBOSE
: s
= "verbose"; break;
707 case REDIS_NOTICE
: s
= "notice"; break;
708 case REDIS_DEBUG
: s
= "debug"; break;
709 default: s
= "unknown"; break; /* too harmless to panic */
711 addReplyBulkCString(c
,"loglevel");
712 addReplyBulkCString(c
,s
);
715 setDeferredMultiBulkLength(c
,replylen
,matches
*2);
718 void configCommand(redisClient
*c
) {
719 if (!strcasecmp(c
->argv
[1]->ptr
,"set")) {
720 if (c
->argc
!= 4) goto badarity
;
722 } else if (!strcasecmp(c
->argv
[1]->ptr
,"get")) {
723 if (c
->argc
!= 3) goto badarity
;
725 } else if (!strcasecmp(c
->argv
[1]->ptr
,"resetstat")) {
726 if (c
->argc
!= 2) goto badarity
;
727 server
.stat_keyspace_hits
= 0;
728 server
.stat_keyspace_misses
= 0;
729 server
.stat_numcommands
= 0;
730 server
.stat_numconnections
= 0;
731 server
.stat_expiredkeys
= 0;
732 resetCommandTableStats();
733 addReply(c
,shared
.ok
);
736 "CONFIG subcommand must be one of GET, SET, RESETSTAT");
741 addReplyErrorFormat(c
,"Wrong number of arguments for CONFIG %s",
742 (char*) c
->argv
[1]->ptr
);