]>
Commit | Line | Data |
---|---|---|
e2641e09 | 1 | #include "redis.h" |
2 | ||
3 | /*----------------------------------------------------------------------------- | |
4 | * Config file parsing | |
5 | *----------------------------------------------------------------------------*/ | |
6 | ||
7 | int yesnotoi(char *s) { | |
8 | if (!strcasecmp(s,"yes")) return 1; | |
9 | else if (!strcasecmp(s,"no")) return 0; | |
10 | else return -1; | |
11 | } | |
12 | ||
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++; | |
18 | } | |
19 | ||
20 | void resetServerSaveParams() { | |
21 | zfree(server.saveparams); | |
22 | server.saveparams = NULL; | |
23 | server.saveparamslen = 0; | |
24 | } | |
25 | ||
67c6f0f6 | 26 | void loadServerConfigFromString(char *config) { |
27 | char *err = NULL; | |
28 | int linenum = 0, totlines, i; | |
29 | sds *lines; | |
e2641e09 | 30 | |
67c6f0f6 | 31 | lines = sdssplitlen(config,strlen(config),"\n",1,&totlines); |
e2641e09 | 32 | |
67c6f0f6 | 33 | for (i = 0; i < totlines; i++) { |
e2641e09 | 34 | sds *argv; |
67c6f0f6 | 35 | int argc; |
e2641e09 | 36 | |
67c6f0f6 | 37 | linenum = i+1; |
38 | lines[i] = sdstrim(lines[i]," \t\r\n"); | |
e2641e09 | 39 | |
40 | /* Skip comments and blank lines*/ | |
67c6f0f6 | 41 | if (lines[i][0] == '#' || lines[i][0] == '\0') continue; |
e2641e09 | 42 | |
43 | /* Split into arguments */ | |
67c6f0f6 | 44 | argv = sdssplitargs(lines[i],&argc); |
e2641e09 | 45 | sdstolower(argv[0]); |
46 | ||
47 | /* Execute config directives */ | |
48 | if (!strcasecmp(argv[0],"timeout") && argc == 2) { | |
49 | server.maxidletime = atoi(argv[1]); | |
50 | if (server.maxidletime < 0) { | |
51 | err = "Invalid timeout value"; goto loaderr; | |
52 | } | |
53 | } else if (!strcasecmp(argv[0],"port") && argc == 2) { | |
54 | server.port = atoi(argv[1]); | |
df50d707 | 55 | if (server.port < 0 || server.port > 65535) { |
e2641e09 | 56 | err = "Invalid port"; goto loaderr; |
57 | } | |
58 | } else if (!strcasecmp(argv[0],"bind") && argc == 2) { | |
59 | server.bindaddr = zstrdup(argv[1]); | |
5d10923f PN |
60 | } else if (!strcasecmp(argv[0],"unixsocket") && argc == 2) { |
61 | server.unixsocket = zstrdup(argv[1]); | |
85238765 | 62 | } else if (!strcasecmp(argv[0],"unixsocketperm") && argc == 2) { |
bb48c5fa | 63 | errno = 0; |
85238765 NF |
64 | server.unixsocketperm = (mode_t)strtol(argv[1], NULL, 8); |
65 | if (errno || server.unixsocketperm > 0777) { | |
66 | err = "Invalid socket file permissions"; goto loaderr; | |
67 | } | |
4aac3ff2 | 68 | } else if (!strcasecmp(argv[0],"save")) { |
69 | if (argc == 3) { | |
70 | int seconds = atoi(argv[1]); | |
71 | int changes = atoi(argv[2]); | |
72 | if (seconds < 1 || changes < 0) { | |
73 | err = "Invalid save parameters"; goto loaderr; | |
74 | } | |
75 | appendServerSaveParams(seconds,changes); | |
76 | } else if (argc == 2 && !strcasecmp(argv[1],"")) { | |
77 | resetServerSaveParams(); | |
e2641e09 | 78 | } |
e2641e09 | 79 | } else if (!strcasecmp(argv[0],"dir") && argc == 2) { |
80 | if (chdir(argv[1]) == -1) { | |
81 | redisLog(REDIS_WARNING,"Can't chdir to '%s': %s", | |
82 | argv[1], strerror(errno)); | |
83 | exit(1); | |
84 | } | |
85 | } else if (!strcasecmp(argv[0],"loglevel") && argc == 2) { | |
86 | if (!strcasecmp(argv[1],"debug")) server.verbosity = REDIS_DEBUG; | |
87 | else if (!strcasecmp(argv[1],"verbose")) server.verbosity = REDIS_VERBOSE; | |
88 | else if (!strcasecmp(argv[1],"notice")) server.verbosity = REDIS_NOTICE; | |
89 | else if (!strcasecmp(argv[1],"warning")) server.verbosity = REDIS_WARNING; | |
90 | else { | |
91 | err = "Invalid log level. Must be one of debug, notice, warning"; | |
92 | goto loaderr; | |
93 | } | |
94 | } else if (!strcasecmp(argv[0],"logfile") && argc == 2) { | |
95 | FILE *logfp; | |
96 | ||
97 | server.logfile = zstrdup(argv[1]); | |
98 | if (!strcasecmp(server.logfile,"stdout")) { | |
99 | zfree(server.logfile); | |
100 | server.logfile = NULL; | |
101 | } | |
102 | if (server.logfile) { | |
103 | /* Test if we are able to open the file. The server will not | |
104 | * be able to abort just for this problem later... */ | |
105 | logfp = fopen(server.logfile,"a"); | |
106 | if (logfp == NULL) { | |
107 | err = sdscatprintf(sdsempty(), | |
108 | "Can't open the log file: %s", strerror(errno)); | |
109 | goto loaderr; | |
110 | } | |
111 | fclose(logfp); | |
112 | } | |
e1a586ee JH |
113 | } else if (!strcasecmp(argv[0],"syslog-enabled") && argc == 2) { |
114 | if ((server.syslog_enabled = yesnotoi(argv[1])) == -1) { | |
115 | err = "argument must be 'yes' or 'no'"; goto loaderr; | |
116 | } | |
117 | } else if (!strcasecmp(argv[0],"syslog-ident") && argc == 2) { | |
118 | if (server.syslog_ident) zfree(server.syslog_ident); | |
119 | server.syslog_ident = zstrdup(argv[1]); | |
120 | } else if (!strcasecmp(argv[0],"syslog-facility") && argc == 2) { | |
121 | struct { | |
122 | const char *name; | |
123 | const int value; | |
124 | } validSyslogFacilities[] = { | |
125 | {"user", LOG_USER}, | |
126 | {"local0", LOG_LOCAL0}, | |
127 | {"local1", LOG_LOCAL1}, | |
128 | {"local2", LOG_LOCAL2}, | |
129 | {"local3", LOG_LOCAL3}, | |
130 | {"local4", LOG_LOCAL4}, | |
131 | {"local5", LOG_LOCAL5}, | |
132 | {"local6", LOG_LOCAL6}, | |
133 | {"local7", LOG_LOCAL7}, | |
134 | {NULL, 0} | |
135 | }; | |
136 | int i; | |
137 | ||
138 | for (i = 0; validSyslogFacilities[i].name; i++) { | |
139 | if (!strcasecmp(validSyslogFacilities[i].name, argv[1])) { | |
140 | server.syslog_facility = validSyslogFacilities[i].value; | |
141 | break; | |
142 | } | |
143 | } | |
144 | ||
145 | if (!validSyslogFacilities[i].name) { | |
146 | err = "Invalid log facility. Must be one of USER or between LOCAL0-LOCAL7"; | |
147 | goto loaderr; | |
148 | } | |
e2641e09 | 149 | } else if (!strcasecmp(argv[0],"databases") && argc == 2) { |
150 | server.dbnum = atoi(argv[1]); | |
151 | if (server.dbnum < 1) { | |
152 | err = "Invalid number of databases"; goto loaderr; | |
153 | } | |
154 | } else if (!strcasecmp(argv[0],"include") && argc == 2) { | |
67c6f0f6 | 155 | loadServerConfig(argv[1],NULL); |
e2641e09 | 156 | } else if (!strcasecmp(argv[0],"maxclients") && argc == 2) { |
157 | server.maxclients = atoi(argv[1]); | |
a5f83412 | 158 | if (server.maxclients < 1) { |
159 | err = "Invalid max clients limit"; goto loaderr; | |
160 | } | |
e2641e09 | 161 | } else if (!strcasecmp(argv[0],"maxmemory") && argc == 2) { |
162 | server.maxmemory = memtoll(argv[1],NULL); | |
165346ca | 163 | } else if (!strcasecmp(argv[0],"maxmemory-policy") && argc == 2) { |
164 | if (!strcasecmp(argv[1],"volatile-lru")) { | |
165 | server.maxmemory_policy = REDIS_MAXMEMORY_VOLATILE_LRU; | |
166 | } else if (!strcasecmp(argv[1],"volatile-random")) { | |
167 | server.maxmemory_policy = REDIS_MAXMEMORY_VOLATILE_RANDOM; | |
168 | } else if (!strcasecmp(argv[1],"volatile-ttl")) { | |
169 | server.maxmemory_policy = REDIS_MAXMEMORY_VOLATILE_TTL; | |
170 | } else if (!strcasecmp(argv[1],"allkeys-lru")) { | |
171 | server.maxmemory_policy = REDIS_MAXMEMORY_ALLKEYS_LRU; | |
172 | } else if (!strcasecmp(argv[1],"allkeys-random")) { | |
173 | server.maxmemory_policy = REDIS_MAXMEMORY_ALLKEYS_RANDOM; | |
5402c426 | 174 | } else if (!strcasecmp(argv[1],"noeviction")) { |
175 | server.maxmemory_policy = REDIS_MAXMEMORY_NO_EVICTION; | |
165346ca | 176 | } else { |
177 | err = "Invalid maxmemory policy"; | |
178 | goto loaderr; | |
179 | } | |
a3687929 | 180 | } else if (!strcasecmp(argv[0],"maxmemory-samples") && argc == 2) { |
181 | server.maxmemory_samples = atoi(argv[1]); | |
182 | if (server.maxmemory_samples <= 0) { | |
183 | err = "maxmemory-samples must be 1 or greater"; | |
184 | goto loaderr; | |
185 | } | |
e2641e09 | 186 | } else if (!strcasecmp(argv[0],"slaveof") && argc == 3) { |
187 | server.masterhost = sdsnew(argv[1]); | |
188 | server.masterport = atoi(argv[2]); | |
1844f990 | 189 | server.repl_state = REDIS_REPL_CONNECT; |
8996bf77 | 190 | } else if (!strcasecmp(argv[0],"repl-ping-slave-period") && argc == 2) { |
191 | server.repl_ping_slave_period = atoi(argv[1]); | |
192 | if (server.repl_ping_slave_period <= 0) { | |
193 | err = "repl-ping-slave-period must be 1 or greater"; | |
194 | goto loaderr; | |
195 | } | |
196 | } else if (!strcasecmp(argv[0],"repl-timeout") && argc == 2) { | |
197 | server.repl_timeout = atoi(argv[1]); | |
198 | if (server.repl_timeout <= 0) { | |
199 | err = "repl-timeout must be 1 or greater"; | |
200 | goto loaderr; | |
201 | } | |
e2641e09 | 202 | } else if (!strcasecmp(argv[0],"masterauth") && argc == 2) { |
203 | server.masterauth = zstrdup(argv[1]); | |
4ebfc455 | 204 | } else if (!strcasecmp(argv[0],"slave-serve-stale-data") && argc == 2) { |
205 | if ((server.repl_serve_stale_data = yesnotoi(argv[1])) == -1) { | |
206 | err = "argument must be 'yes' or 'no'"; goto loaderr; | |
207 | } | |
f3fd419f | 208 | } else if (!strcasecmp(argv[0],"slave-read-only") && argc == 2) { |
209 | if ((server.repl_slave_ro = yesnotoi(argv[1])) == -1) { | |
210 | err = "argument must be 'yes' or 'no'"; goto loaderr; | |
211 | } | |
e2641e09 | 212 | } else if (!strcasecmp(argv[0],"rdbcompression") && argc == 2) { |
f48cd4b9 | 213 | if ((server.rdb_compression = yesnotoi(argv[1])) == -1) { |
e2641e09 | 214 | err = "argument must be 'yes' or 'no'"; goto loaderr; |
215 | } | |
84bcd3aa | 216 | } else if (!strcasecmp(argv[0],"rdbchecksum") && argc == 2) { |
217 | if ((server.rdb_checksum = yesnotoi(argv[1])) == -1) { | |
218 | err = "argument must be 'yes' or 'no'"; goto loaderr; | |
219 | } | |
e2641e09 | 220 | } else if (!strcasecmp(argv[0],"activerehashing") && argc == 2) { |
221 | if ((server.activerehashing = yesnotoi(argv[1])) == -1) { | |
222 | err = "argument must be 'yes' or 'no'"; goto loaderr; | |
223 | } | |
224 | } else if (!strcasecmp(argv[0],"daemonize") && argc == 2) { | |
225 | if ((server.daemonize = yesnotoi(argv[1])) == -1) { | |
226 | err = "argument must be 'yes' or 'no'"; goto loaderr; | |
227 | } | |
228 | } else if (!strcasecmp(argv[0],"appendonly") && argc == 2) { | |
e394114d | 229 | int yes; |
230 | ||
231 | if ((yes = yesnotoi(argv[1])) == -1) { | |
e2641e09 | 232 | err = "argument must be 'yes' or 'no'"; goto loaderr; |
233 | } | |
e394114d | 234 | server.aof_state = yes ? REDIS_AOF_ON : REDIS_AOF_OFF; |
e2641e09 | 235 | } else if (!strcasecmp(argv[0],"appendfilename") && argc == 2) { |
2c915bcf | 236 | zfree(server.aof_filename); |
237 | server.aof_filename = zstrdup(argv[1]); | |
e2641e09 | 238 | } else if (!strcasecmp(argv[0],"no-appendfsync-on-rewrite") |
239 | && argc == 2) { | |
2c915bcf | 240 | if ((server.aof_no_fsync_on_rewrite= yesnotoi(argv[1])) == -1) { |
e2641e09 | 241 | err = "argument must be 'yes' or 'no'"; goto loaderr; |
242 | } | |
243 | } else if (!strcasecmp(argv[0],"appendfsync") && argc == 2) { | |
244 | if (!strcasecmp(argv[1],"no")) { | |
2c915bcf | 245 | server.aof_fsync = AOF_FSYNC_NO; |
e2641e09 | 246 | } else if (!strcasecmp(argv[1],"always")) { |
2c915bcf | 247 | server.aof_fsync = AOF_FSYNC_ALWAYS; |
e2641e09 | 248 | } else if (!strcasecmp(argv[1],"everysec")) { |
2c915bcf | 249 | server.aof_fsync = AOF_FSYNC_EVERYSEC; |
e2641e09 | 250 | } else { |
251 | err = "argument must be 'no', 'always' or 'everysec'"; | |
252 | goto loaderr; | |
253 | } | |
b333e239 | 254 | } else if (!strcasecmp(argv[0],"auto-aof-rewrite-percentage") && |
255 | argc == 2) | |
256 | { | |
2c915bcf | 257 | server.aof_rewrite_perc = atoi(argv[1]); |
258 | if (server.aof_rewrite_perc < 0) { | |
b333e239 | 259 | err = "Invalid negative percentage for AOF auto rewrite"; |
260 | goto loaderr; | |
261 | } | |
262 | } else if (!strcasecmp(argv[0],"auto-aof-rewrite-min-size") && | |
263 | argc == 2) | |
264 | { | |
2c915bcf | 265 | server.aof_rewrite_min_size = memtoll(argv[1],NULL); |
e2641e09 | 266 | } else if (!strcasecmp(argv[0],"requirepass") && argc == 2) { |
31a1439b | 267 | if (strlen(argv[1]) > REDIS_AUTHPASS_MAX_LEN) { |
268 | err = "Password is longer than REDIS_AUTHPASS_MAX_LEN"; | |
269 | goto loaderr; | |
270 | } | |
e2641e09 | 271 | server.requirepass = zstrdup(argv[1]); |
272 | } else if (!strcasecmp(argv[0],"pidfile") && argc == 2) { | |
273 | zfree(server.pidfile); | |
274 | server.pidfile = zstrdup(argv[1]); | |
275 | } else if (!strcasecmp(argv[0],"dbfilename") && argc == 2) { | |
f48cd4b9 | 276 | zfree(server.rdb_filename); |
277 | server.rdb_filename = zstrdup(argv[1]); | |
ebd85e9a PN |
278 | } else if (!strcasecmp(argv[0],"hash-max-ziplist-entries") && argc == 2) { |
279 | server.hash_max_ziplist_entries = memtoll(argv[1], NULL); | |
280 | } else if (!strcasecmp(argv[0],"hash-max-ziplist-value") && argc == 2) { | |
281 | server.hash_max_ziplist_value = memtoll(argv[1], NULL); | |
e2641e09 | 282 | } else if (!strcasecmp(argv[0],"list-max-ziplist-entries") && argc == 2){ |
283 | server.list_max_ziplist_entries = memtoll(argv[1], NULL); | |
8d3e063a | 284 | } else if (!strcasecmp(argv[0],"list-max-ziplist-value") && argc == 2) { |
e2641e09 | 285 | server.list_max_ziplist_value = memtoll(argv[1], NULL); |
8d3e063a | 286 | } else if (!strcasecmp(argv[0],"set-max-intset-entries") && argc == 2) { |
96ffb2fe | 287 | server.set_max_intset_entries = memtoll(argv[1], NULL); |
3ea204e1 PN |
288 | } else if (!strcasecmp(argv[0],"zset-max-ziplist-entries") && argc == 2) { |
289 | server.zset_max_ziplist_entries = memtoll(argv[1], NULL); | |
290 | } else if (!strcasecmp(argv[0],"zset-max-ziplist-value") && argc == 2) { | |
291 | server.zset_max_ziplist_value = memtoll(argv[1], NULL); | |
8d3e063a | 292 | } else if (!strcasecmp(argv[0],"rename-command") && argc == 3) { |
293 | struct redisCommand *cmd = lookupCommand(argv[1]); | |
294 | int retval; | |
295 | ||
296 | if (!cmd) { | |
297 | err = "No such command in rename-command"; | |
298 | goto loaderr; | |
299 | } | |
300 | ||
301 | /* If the target command name is the emtpy string we just | |
302 | * remove it from the command table. */ | |
303 | retval = dictDelete(server.commands, argv[1]); | |
304 | redisAssert(retval == DICT_OK); | |
305 | ||
306 | /* Otherwise we re-add the command under a different name. */ | |
307 | if (sdslen(argv[2]) != 0) { | |
308 | sds copy = sdsdup(argv[2]); | |
309 | ||
310 | retval = dictAdd(server.commands, copy, cmd); | |
311 | if (retval != DICT_OK) { | |
312 | sdsfree(copy); | |
313 | err = "Target command name already exists"; goto loaderr; | |
314 | } | |
315 | } | |
ecc91094 | 316 | } else if (!strcasecmp(argv[0],"cluster-enabled") && argc == 2) { |
317 | if ((server.cluster_enabled = yesnotoi(argv[1])) == -1) { | |
318 | err = "argument must be 'yes' or 'no'"; goto loaderr; | |
319 | } | |
1793752d | 320 | } else if (!strcasecmp(argv[0],"cluster-config-file") && argc == 2) { |
321 | zfree(server.cluster.configfile); | |
322 | server.cluster.configfile = zstrdup(argv[1]); | |
eeffcf38 | 323 | } else if (!strcasecmp(argv[0],"lua-time-limit") && argc == 2) { |
324 | server.lua_time_limit = strtoll(argv[1],NULL,10); | |
35a60441 | 325 | } else if (!strcasecmp(argv[0],"slowlog-log-slower-than") && |
326 | argc == 2) | |
327 | { | |
328 | server.slowlog_log_slower_than = strtoll(argv[1],NULL,10); | |
329 | } else if (!strcasecmp(argv[0],"slowlog-max-len") && argc == 2) { | |
330 | server.slowlog_max_len = strtoll(argv[1],NULL,10); | |
7fe8d49a | 331 | } else if (!strcasecmp(argv[0],"client-output-buffer-limit") && |
332 | argc == 5) | |
333 | { | |
334 | int class = getClientLimitClassByName(argv[1]); | |
335 | unsigned long long hard, soft; | |
336 | int soft_seconds; | |
337 | ||
338 | if (class == -1) { | |
339 | err = "Unrecognized client limit class"; | |
340 | goto loaderr; | |
341 | } | |
342 | hard = memtoll(argv[2],NULL); | |
343 | soft = memtoll(argv[3],NULL); | |
344 | soft_seconds = atoi(argv[4]); | |
345 | if (soft_seconds < 0) { | |
346 | err = "Negative number of seconds in soft limt is invalid"; | |
347 | goto loaderr; | |
348 | } | |
349 | server.client_obuf_limits[class].hard_limit_bytes = hard; | |
350 | server.client_obuf_limits[class].soft_limit_bytes = soft; | |
351 | server.client_obuf_limits[class].soft_limit_seconds = soft_seconds; | |
4d3bbf35 | 352 | } else if (!strcasecmp(argv[0],"stop-writes-on-bgsave-error") && |
353 | argc == 2) { | |
354 | if ((server.stop_writes_on_bgsave_err = yesnotoi(argv[1])) == -1) { | |
355 | err = "argument must be 'yes' or 'no'"; goto loaderr; | |
356 | } | |
169a44cb | 357 | } else if (!strcasecmp(argv[0],"slave-priority") && argc == 2) { |
358 | server.slave_priority = atoi(argv[1]); | |
6b5daa2d | 359 | } else if (!strcasecmp(argv[0],"sentinel")) { |
360 | /* argc == 1 is handled by main() as we need to enter the sentinel | |
361 | * mode ASAP. */ | |
362 | if (argc != 1) { | |
363 | if (!server.sentinel_mode) { | |
364 | err = "sentinel directive while not in sentinel mode"; | |
365 | goto loaderr; | |
366 | } | |
367 | err = sentinelHandleConfiguration(argv+1,argc-1); | |
368 | if (err) goto loaderr; | |
369 | } | |
e2641e09 | 370 | } else { |
371 | err = "Bad directive or wrong number of arguments"; goto loaderr; | |
372 | } | |
67c6f0f6 | 373 | sdsfreesplitres(argv,argc); |
e2641e09 | 374 | } |
67c6f0f6 | 375 | sdsfreesplitres(lines,totlines); |
e2641e09 | 376 | return; |
377 | ||
378 | loaderr: | |
379 | fprintf(stderr, "\n*** FATAL CONFIG FILE ERROR ***\n"); | |
380 | fprintf(stderr, "Reading the configuration file, at line %d\n", linenum); | |
67c6f0f6 | 381 | fprintf(stderr, ">>> '%s'\n", lines[i]); |
e2641e09 | 382 | fprintf(stderr, "%s\n", err); |
383 | exit(1); | |
384 | } | |
385 | ||
67c6f0f6 | 386 | /* Load the server configuration from the specified filename. |
387 | * The function appends the additional configuration directives stored | |
388 | * in the 'options' string to the config file before loading. | |
389 | * | |
390 | * Both filename and options can be NULL, in such a case are considered | |
391 | * emtpy. This way loadServerConfig can be used to just load a file or | |
392 | * just load a string. */ | |
393 | void loadServerConfig(char *filename, char *options) { | |
394 | sds config = sdsempty(); | |
395 | char buf[REDIS_CONFIGLINE_MAX+1]; | |
396 | ||
397 | /* Load the file content */ | |
398 | if (filename) { | |
399 | FILE *fp; | |
400 | ||
401 | if (filename[0] == '-' && filename[1] == '\0') { | |
402 | fp = stdin; | |
403 | } else { | |
404 | if ((fp = fopen(filename,"r")) == NULL) { | |
405 | redisLog(REDIS_WARNING, | |
406 | "Fatal error, can't open config file '%s'", filename); | |
407 | exit(1); | |
408 | } | |
409 | } | |
410 | while(fgets(buf,REDIS_CONFIGLINE_MAX+1,fp) != NULL) | |
411 | config = sdscat(config,buf); | |
412 | if (fp != stdin) fclose(fp); | |
413 | } | |
414 | /* Append the additional options */ | |
415 | if (options) { | |
416 | config = sdscat(config,"\n"); | |
417 | config = sdscat(config,options); | |
418 | } | |
419 | loadServerConfigFromString(config); | |
420 | sdsfree(config); | |
421 | } | |
422 | ||
e2641e09 | 423 | /*----------------------------------------------------------------------------- |
424 | * CONFIG command for remote configuration | |
425 | *----------------------------------------------------------------------------*/ | |
426 | ||
427 | void configSetCommand(redisClient *c) { | |
a375b077 | 428 | robj *o; |
e2641e09 | 429 | long long ll; |
eab0e26e | 430 | redisAssertWithInfo(c,c->argv[2],c->argv[2]->encoding == REDIS_ENCODING_RAW); |
431 | redisAssertWithInfo(c,c->argv[2],c->argv[3]->encoding == REDIS_ENCODING_RAW); | |
a375b077 | 432 | o = c->argv[3]; |
e2641e09 | 433 | |
434 | if (!strcasecmp(c->argv[2]->ptr,"dbfilename")) { | |
f48cd4b9 | 435 | zfree(server.rdb_filename); |
436 | server.rdb_filename = zstrdup(o->ptr); | |
e2641e09 | 437 | } else if (!strcasecmp(c->argv[2]->ptr,"requirepass")) { |
31a1439b | 438 | if (sdslen(o->ptr) > REDIS_AUTHPASS_MAX_LEN) goto badfmt; |
e2641e09 | 439 | zfree(server.requirepass); |
1eceb85e | 440 | server.requirepass = ((char*)o->ptr)[0] ? zstrdup(o->ptr) : NULL; |
e2641e09 | 441 | } else if (!strcasecmp(c->argv[2]->ptr,"masterauth")) { |
442 | zfree(server.masterauth); | |
443 | server.masterauth = zstrdup(o->ptr); | |
444 | } else if (!strcasecmp(c->argv[2]->ptr,"maxmemory")) { | |
445 | if (getLongLongFromObject(o,&ll) == REDIS_ERR || | |
446 | ll < 0) goto badfmt; | |
447 | server.maxmemory = ll; | |
b4f2e412 | 448 | if (server.maxmemory) freeMemoryIfNeeded(); |
165346ca | 449 | } else if (!strcasecmp(c->argv[2]->ptr,"maxmemory-policy")) { |
450 | if (!strcasecmp(o->ptr,"volatile-lru")) { | |
451 | server.maxmemory_policy = REDIS_MAXMEMORY_VOLATILE_LRU; | |
452 | } else if (!strcasecmp(o->ptr,"volatile-random")) { | |
453 | server.maxmemory_policy = REDIS_MAXMEMORY_VOLATILE_RANDOM; | |
454 | } else if (!strcasecmp(o->ptr,"volatile-ttl")) { | |
455 | server.maxmemory_policy = REDIS_MAXMEMORY_VOLATILE_TTL; | |
456 | } else if (!strcasecmp(o->ptr,"allkeys-lru")) { | |
457 | server.maxmemory_policy = REDIS_MAXMEMORY_ALLKEYS_LRU; | |
458 | } else if (!strcasecmp(o->ptr,"allkeys-random")) { | |
459 | server.maxmemory_policy = REDIS_MAXMEMORY_ALLKEYS_RANDOM; | |
5402c426 | 460 | } else if (!strcasecmp(o->ptr,"noeviction")) { |
461 | server.maxmemory_policy = REDIS_MAXMEMORY_NO_EVICTION; | |
165346ca | 462 | } else { |
463 | goto badfmt; | |
464 | } | |
a3687929 | 465 | } else if (!strcasecmp(c->argv[2]->ptr,"maxmemory-samples")) { |
466 | if (getLongLongFromObject(o,&ll) == REDIS_ERR || | |
467 | ll <= 0) goto badfmt; | |
468 | server.maxmemory_samples = ll; | |
e2641e09 | 469 | } else if (!strcasecmp(c->argv[2]->ptr,"timeout")) { |
470 | if (getLongLongFromObject(o,&ll) == REDIS_ERR || | |
471 | ll < 0 || ll > LONG_MAX) goto badfmt; | |
472 | server.maxidletime = ll; | |
473 | } else if (!strcasecmp(c->argv[2]->ptr,"appendfsync")) { | |
474 | if (!strcasecmp(o->ptr,"no")) { | |
2c915bcf | 475 | server.aof_fsync = AOF_FSYNC_NO; |
e2641e09 | 476 | } else if (!strcasecmp(o->ptr,"everysec")) { |
2c915bcf | 477 | server.aof_fsync = AOF_FSYNC_EVERYSEC; |
e2641e09 | 478 | } else if (!strcasecmp(o->ptr,"always")) { |
2c915bcf | 479 | server.aof_fsync = AOF_FSYNC_ALWAYS; |
e2641e09 | 480 | } else { |
481 | goto badfmt; | |
482 | } | |
483 | } else if (!strcasecmp(c->argv[2]->ptr,"no-appendfsync-on-rewrite")) { | |
484 | int yn = yesnotoi(o->ptr); | |
485 | ||
486 | if (yn == -1) goto badfmt; | |
2c915bcf | 487 | server.aof_no_fsync_on_rewrite = yn; |
e2641e09 | 488 | } else if (!strcasecmp(c->argv[2]->ptr,"appendonly")) { |
e394114d | 489 | int enable = yesnotoi(o->ptr); |
490 | ||
491 | if (enable == -1) goto badfmt; | |
492 | if (enable == 0 && server.aof_state != REDIS_AOF_OFF) { | |
493 | stopAppendOnly(); | |
494 | } else if (enable && server.aof_state == REDIS_AOF_OFF) { | |
495 | if (startAppendOnly() == REDIS_ERR) { | |
496 | addReplyError(c, | |
497 | "Unable to turn on AOF. Check server logs."); | |
498 | return; | |
e2641e09 | 499 | } |
500 | } | |
0ec93220 | 501 | } else if (!strcasecmp(c->argv[2]->ptr,"auto-aof-rewrite-percentage")) { |
502 | if (getLongLongFromObject(o,&ll) == REDIS_ERR || ll < 0) goto badfmt; | |
2c915bcf | 503 | server.aof_rewrite_perc = ll; |
0ec93220 | 504 | } else if (!strcasecmp(c->argv[2]->ptr,"auto-aof-rewrite-min-size")) { |
505 | if (getLongLongFromObject(o,&ll) == REDIS_ERR || ll < 0) goto badfmt; | |
2c915bcf | 506 | server.aof_rewrite_min_size = ll; |
e2641e09 | 507 | } else if (!strcasecmp(c->argv[2]->ptr,"save")) { |
508 | int vlen, j; | |
509 | sds *v = sdssplitlen(o->ptr,sdslen(o->ptr)," ",1,&vlen); | |
510 | ||
511 | /* Perform sanity check before setting the new config: | |
512 | * - Even number of args | |
513 | * - Seconds >= 1, changes >= 0 */ | |
514 | if (vlen & 1) { | |
515 | sdsfreesplitres(v,vlen); | |
516 | goto badfmt; | |
517 | } | |
518 | for (j = 0; j < vlen; j++) { | |
519 | char *eptr; | |
520 | long val; | |
521 | ||
522 | val = strtoll(v[j], &eptr, 10); | |
523 | if (eptr[0] != '\0' || | |
524 | ((j & 1) == 0 && val < 1) || | |
525 | ((j & 1) == 1 && val < 0)) { | |
526 | sdsfreesplitres(v,vlen); | |
527 | goto badfmt; | |
528 | } | |
529 | } | |
530 | /* Finally set the new config */ | |
531 | resetServerSaveParams(); | |
532 | for (j = 0; j < vlen; j += 2) { | |
533 | time_t seconds; | |
534 | int changes; | |
535 | ||
536 | seconds = strtoll(v[j],NULL,10); | |
537 | changes = strtoll(v[j+1],NULL,10); | |
538 | appendServerSaveParams(seconds, changes); | |
539 | } | |
540 | sdsfreesplitres(v,vlen); | |
4ebfc455 | 541 | } else if (!strcasecmp(c->argv[2]->ptr,"slave-serve-stale-data")) { |
542 | int yn = yesnotoi(o->ptr); | |
543 | ||
544 | if (yn == -1) goto badfmt; | |
545 | server.repl_serve_stale_data = yn; | |
f3fd419f | 546 | } else if (!strcasecmp(c->argv[2]->ptr,"slave-read-only")) { |
547 | int yn = yesnotoi(o->ptr); | |
548 | ||
549 | if (yn == -1) goto badfmt; | |
550 | server.repl_slave_ro = yn; | |
21cda08b | 551 | } else if (!strcasecmp(c->argv[2]->ptr,"dir")) { |
552 | if (chdir((char*)o->ptr) == -1) { | |
553 | addReplyErrorFormat(c,"Changing directory: %s", strerror(errno)); | |
554 | return; | |
555 | } | |
ebd85e9a | 556 | } else if (!strcasecmp(c->argv[2]->ptr,"hash-max-ziplist-entries")) { |
465b4189 | 557 | if (getLongLongFromObject(o,&ll) == REDIS_ERR || ll < 0) goto badfmt; |
ebd85e9a PN |
558 | server.hash_max_ziplist_entries = ll; |
559 | } else if (!strcasecmp(c->argv[2]->ptr,"hash-max-ziplist-value")) { | |
465b4189 | 560 | if (getLongLongFromObject(o,&ll) == REDIS_ERR || ll < 0) goto badfmt; |
ebd85e9a | 561 | server.hash_max_ziplist_value = ll; |
465b4189 | 562 | } else if (!strcasecmp(c->argv[2]->ptr,"list-max-ziplist-entries")) { |
563 | if (getLongLongFromObject(o,&ll) == REDIS_ERR || ll < 0) goto badfmt; | |
564 | server.list_max_ziplist_entries = ll; | |
565 | } else if (!strcasecmp(c->argv[2]->ptr,"list-max-ziplist-value")) { | |
566 | if (getLongLongFromObject(o,&ll) == REDIS_ERR || ll < 0) goto badfmt; | |
567 | server.list_max_ziplist_value = ll; | |
568 | } else if (!strcasecmp(c->argv[2]->ptr,"set-max-intset-entries")) { | |
569 | if (getLongLongFromObject(o,&ll) == REDIS_ERR || ll < 0) goto badfmt; | |
570 | server.set_max_intset_entries = ll; | |
3ea204e1 PN |
571 | } else if (!strcasecmp(c->argv[2]->ptr,"zset-max-ziplist-entries")) { |
572 | if (getLongLongFromObject(o,&ll) == REDIS_ERR || ll < 0) goto badfmt; | |
573 | server.zset_max_ziplist_entries = ll; | |
574 | } else if (!strcasecmp(c->argv[2]->ptr,"zset-max-ziplist-value")) { | |
575 | if (getLongLongFromObject(o,&ll) == REDIS_ERR || ll < 0) goto badfmt; | |
576 | server.zset_max_ziplist_value = ll; | |
eeffcf38 | 577 | } else if (!strcasecmp(c->argv[2]->ptr,"lua-time-limit")) { |
578 | if (getLongLongFromObject(o,&ll) == REDIS_ERR || ll < 0) goto badfmt; | |
579 | server.lua_time_limit = ll; | |
35a60441 | 580 | } else if (!strcasecmp(c->argv[2]->ptr,"slowlog-log-slower-than")) { |
581 | if (getLongLongFromObject(o,&ll) == REDIS_ERR) goto badfmt; | |
582 | server.slowlog_log_slower_than = ll; | |
583 | } else if (!strcasecmp(c->argv[2]->ptr,"slowlog-max-len")) { | |
584 | if (getLongLongFromObject(o,&ll) == REDIS_ERR || ll < 0) goto badfmt; | |
585 | server.slowlog_max_len = (unsigned)ll; | |
2aa26d2a | 586 | } else if (!strcasecmp(c->argv[2]->ptr,"loglevel")) { |
587 | if (!strcasecmp(o->ptr,"warning")) { | |
588 | server.verbosity = REDIS_WARNING; | |
589 | } else if (!strcasecmp(o->ptr,"notice")) { | |
590 | server.verbosity = REDIS_NOTICE; | |
591 | } else if (!strcasecmp(o->ptr,"verbose")) { | |
592 | server.verbosity = REDIS_VERBOSE; | |
593 | } else if (!strcasecmp(o->ptr,"debug")) { | |
594 | server.verbosity = REDIS_DEBUG; | |
595 | } else { | |
596 | goto badfmt; | |
597 | } | |
7fe8d49a | 598 | } else if (!strcasecmp(c->argv[2]->ptr,"client-output-buffer-limit")) { |
599 | int vlen, j; | |
600 | sds *v = sdssplitlen(o->ptr,sdslen(o->ptr)," ",1,&vlen); | |
601 | ||
602 | /* We need a multiple of 4: <class> <hard> <soft> <soft_seconds> */ | |
603 | if (vlen % 4) { | |
604 | sdsfreesplitres(v,vlen); | |
605 | goto badfmt; | |
606 | } | |
607 | ||
608 | /* Sanity check of single arguments, so that we either refuse the | |
609 | * whole configuration string or accept it all, even if a single | |
610 | * error in a single client class is present. */ | |
611 | for (j = 0; j < vlen; j++) { | |
612 | char *eptr; | |
613 | long val; | |
614 | ||
615 | if ((j % 4) == 0) { | |
616 | if (getClientLimitClassByName(v[j]) == -1) { | |
617 | sdsfreesplitres(v,vlen); | |
618 | goto badfmt; | |
619 | } | |
620 | } else { | |
621 | val = strtoll(v[j], &eptr, 10); | |
622 | if (eptr[0] != '\0' || val < 0) { | |
623 | sdsfreesplitres(v,vlen); | |
624 | goto badfmt; | |
625 | } | |
626 | } | |
627 | } | |
628 | /* Finally set the new config */ | |
629 | for (j = 0; j < vlen; j += 4) { | |
630 | int class; | |
631 | unsigned long long hard, soft; | |
632 | int soft_seconds; | |
633 | ||
634 | class = getClientLimitClassByName(v[j]); | |
635 | hard = strtoll(v[j+1],NULL,10); | |
636 | soft = strtoll(v[j+2],NULL,10); | |
637 | soft_seconds = strtoll(v[j+3],NULL,10); | |
638 | ||
639 | server.client_obuf_limits[class].hard_limit_bytes = hard; | |
640 | server.client_obuf_limits[class].soft_limit_bytes = soft; | |
641 | server.client_obuf_limits[class].soft_limit_seconds = soft_seconds; | |
642 | } | |
643 | sdsfreesplitres(v,vlen); | |
4d3bbf35 | 644 | } else if (!strcasecmp(c->argv[2]->ptr,"stop-writes-on-bgsave-error")) { |
645 | int yn = yesnotoi(o->ptr); | |
7fe8d49a | 646 | |
4d3bbf35 | 647 | if (yn == -1) goto badfmt; |
648 | server.stop_writes_on_bgsave_err = yn; | |
0823e48f | 649 | } else if (!strcasecmp(c->argv[2]->ptr,"repl-ping-slave-period")) { |
650 | if (getLongLongFromObject(o,&ll) == REDIS_ERR || ll <= 0) goto badfmt; | |
651 | server.repl_ping_slave_period = ll; | |
652 | } else if (!strcasecmp(c->argv[2]->ptr,"repl-timeout")) { | |
653 | if (getLongLongFromObject(o,&ll) == REDIS_ERR || ll <= 0) goto badfmt; | |
654 | server.repl_timeout = ll; | |
39bd025c | 655 | } else if (!strcasecmp(c->argv[2]->ptr,"watchdog-period")) { |
656 | if (getLongLongFromObject(o,&ll) == REDIS_ERR || ll < 0) goto badfmt; | |
657 | if (ll) | |
658 | enableWatchdog(ll); | |
659 | else | |
660 | disableWatchdog(); | |
84bcd3aa | 661 | } else if (!strcasecmp(c->argv[2]->ptr,"rdbcompression")) { |
662 | int yn = yesnotoi(o->ptr); | |
663 | ||
664 | if (yn == -1) goto badfmt; | |
665 | server.rdb_compression = yn; | |
666 | } else if (!strcasecmp(c->argv[2]->ptr,"rdbchecksum")) { | |
667 | int yn = yesnotoi(o->ptr); | |
668 | ||
669 | if (yn == -1) goto badfmt; | |
670 | server.rdb_checksum = yn; | |
169a44cb | 671 | } else if (!strcasecmp(c->argv[2]->ptr,"slave-priority")) { |
672 | if (getLongLongFromObject(o,&ll) == REDIS_ERR || | |
673 | ll <= 0) goto badfmt; | |
674 | server.slave_priority = ll; | |
e2641e09 | 675 | } else { |
3ab20376 PN |
676 | addReplyErrorFormat(c,"Unsupported CONFIG parameter: %s", |
677 | (char*)c->argv[2]->ptr); | |
e2641e09 | 678 | return; |
679 | } | |
e2641e09 | 680 | addReply(c,shared.ok); |
681 | return; | |
682 | ||
683 | badfmt: /* Bad format errors */ | |
3ab20376 | 684 | addReplyErrorFormat(c,"Invalid argument '%s' for CONFIG SET '%s'", |
e2641e09 | 685 | (char*)o->ptr, |
3ab20376 | 686 | (char*)c->argv[2]->ptr); |
e2641e09 | 687 | } |
688 | ||
0823e48f | 689 | #define config_get_string_field(_name,_var) do { \ |
690 | if (stringmatch(pattern,_name,0)) { \ | |
691 | addReplyBulkCString(c,_name); \ | |
692 | addReplyBulkCString(c,_var ? _var : ""); \ | |
693 | matches++; \ | |
694 | } \ | |
695 | } while(0); | |
696 | ||
697 | #define config_get_bool_field(_name,_var) do { \ | |
698 | if (stringmatch(pattern,_name,0)) { \ | |
699 | addReplyBulkCString(c,_name); \ | |
700 | addReplyBulkCString(c,_var ? "yes" : "no"); \ | |
701 | matches++; \ | |
702 | } \ | |
703 | } while(0); | |
704 | ||
705 | #define config_get_numerical_field(_name,_var) do { \ | |
706 | if (stringmatch(pattern,_name,0)) { \ | |
707 | ll2string(buf,sizeof(buf),_var); \ | |
708 | addReplyBulkCString(c,_name); \ | |
709 | addReplyBulkCString(c,buf); \ | |
710 | matches++; \ | |
711 | } \ | |
712 | } while(0); | |
713 | ||
e2641e09 | 714 | void configGetCommand(redisClient *c) { |
a375b077 | 715 | robj *o = c->argv[2]; |
b301c1fc | 716 | void *replylen = addDeferredMultiBulkLength(c); |
e2641e09 | 717 | char *pattern = o->ptr; |
a3687929 | 718 | char buf[128]; |
e2641e09 | 719 | int matches = 0; |
eab0e26e | 720 | redisAssertWithInfo(c,o,o->encoding == REDIS_ENCODING_RAW); |
e2641e09 | 721 | |
0823e48f | 722 | /* String values */ |
723 | config_get_string_field("dbfilename",server.rdb_filename); | |
724 | config_get_string_field("requirepass",server.requirepass); | |
725 | config_get_string_field("masterauth",server.requirepass); | |
726 | config_get_string_field("bind",server.bindaddr); | |
727 | config_get_string_field("unixsocket",server.unixsocket); | |
728 | config_get_string_field("logfile",server.logfile); | |
729 | config_get_string_field("pidfile",server.pidfile); | |
730 | ||
731 | /* Numerical values */ | |
732 | config_get_numerical_field("maxmemory",server.maxmemory); | |
733 | config_get_numerical_field("maxmemory-samples",server.maxmemory_samples); | |
734 | config_get_numerical_field("timeout",server.maxidletime); | |
735 | config_get_numerical_field("auto-aof-rewrite-percentage", | |
736 | server.aof_rewrite_perc); | |
737 | config_get_numerical_field("auto-aof-rewrite-min-size", | |
738 | server.aof_rewrite_min_size); | |
85627983 | 739 | config_get_numerical_field("hash-max-ziplist-entries", |
740 | server.hash_max_ziplist_entries); | |
741 | config_get_numerical_field("hash-max-ziplist-value", | |
742 | server.hash_max_ziplist_value); | |
0823e48f | 743 | config_get_numerical_field("list-max-ziplist-entries", |
744 | server.list_max_ziplist_entries); | |
745 | config_get_numerical_field("list-max-ziplist-value", | |
746 | server.list_max_ziplist_value); | |
747 | config_get_numerical_field("set-max-intset-entries", | |
748 | server.set_max_intset_entries); | |
749 | config_get_numerical_field("zset-max-ziplist-entries", | |
750 | server.zset_max_ziplist_entries); | |
751 | config_get_numerical_field("zset-max-ziplist-value", | |
752 | server.zset_max_ziplist_value); | |
753 | config_get_numerical_field("lua-time-limit",server.lua_time_limit); | |
754 | config_get_numerical_field("slowlog-log-slower-than", | |
755 | server.slowlog_log_slower_than); | |
756 | config_get_numerical_field("slowlog-max-len", | |
757 | server.slowlog_max_len); | |
758 | config_get_numerical_field("port",server.port); | |
759 | config_get_numerical_field("databases",server.dbnum); | |
760 | config_get_numerical_field("repl-ping-slave-period",server.repl_ping_slave_period); | |
761 | config_get_numerical_field("repl-timeout",server.repl_timeout); | |
762 | config_get_numerical_field("maxclients",server.maxclients); | |
39bd025c | 763 | config_get_numerical_field("watchdog-period",server.watchdog_period); |
169a44cb | 764 | config_get_numerical_field("slave-priority",server.slave_priority); |
0823e48f | 765 | |
766 | /* Bool (yes/no) values */ | |
767 | config_get_bool_field("no-appendfsync-on-rewrite", | |
768 | server.aof_no_fsync_on_rewrite); | |
769 | config_get_bool_field("slave-serve-stale-data", | |
770 | server.repl_serve_stale_data); | |
f3fd419f | 771 | config_get_bool_field("slave-read-only", |
772 | server.repl_slave_ro); | |
0823e48f | 773 | config_get_bool_field("stop-writes-on-bgsave-error", |
774 | server.stop_writes_on_bgsave_err); | |
775 | config_get_bool_field("daemonize", server.daemonize); | |
776 | config_get_bool_field("rdbcompression", server.rdb_compression); | |
84bcd3aa | 777 | config_get_bool_field("rdbchecksum", server.rdb_checksum); |
0823e48f | 778 | config_get_bool_field("activerehashing", server.activerehashing); |
779 | ||
780 | /* Everything we can't handle with macros follows. */ | |
781 | ||
782 | if (stringmatch(pattern,"appendonly",0)) { | |
783 | addReplyBulkCString(c,"appendonly"); | |
784 | addReplyBulkCString(c,server.aof_state == REDIS_AOF_OFF ? "no" : "yes"); | |
785 | matches++; | |
786 | } | |
21cda08b | 787 | if (stringmatch(pattern,"dir",0)) { |
788 | char buf[1024]; | |
789 | ||
bb831c31 | 790 | if (getcwd(buf,sizeof(buf)) == NULL) |
09d2abdc | 791 | buf[0] = '\0'; |
bb831c31 PN |
792 | |
793 | addReplyBulkCString(c,"dir"); | |
794 | addReplyBulkCString(c,buf); | |
21cda08b | 795 | matches++; |
796 | } | |
165346ca | 797 | if (stringmatch(pattern,"maxmemory-policy",0)) { |
798 | char *s; | |
799 | ||
800 | switch(server.maxmemory_policy) { | |
801 | case REDIS_MAXMEMORY_VOLATILE_LRU: s = "volatile-lru"; break; | |
802 | case REDIS_MAXMEMORY_VOLATILE_TTL: s = "volatile-ttl"; break; | |
803 | case REDIS_MAXMEMORY_VOLATILE_RANDOM: s = "volatile-random"; break; | |
804 | case REDIS_MAXMEMORY_ALLKEYS_LRU: s = "allkeys-lru"; break; | |
805 | case REDIS_MAXMEMORY_ALLKEYS_RANDOM: s = "allkeys-random"; break; | |
5402c426 | 806 | case REDIS_MAXMEMORY_NO_EVICTION: s = "noeviction"; break; |
165346ca | 807 | default: s = "unknown"; break; /* too harmless to panic */ |
808 | } | |
809 | addReplyBulkCString(c,"maxmemory-policy"); | |
810 | addReplyBulkCString(c,s); | |
811 | matches++; | |
812 | } | |
e2641e09 | 813 | if (stringmatch(pattern,"appendfsync",0)) { |
814 | char *policy; | |
815 | ||
2c915bcf | 816 | switch(server.aof_fsync) { |
817 | case AOF_FSYNC_NO: policy = "no"; break; | |
818 | case AOF_FSYNC_EVERYSEC: policy = "everysec"; break; | |
819 | case AOF_FSYNC_ALWAYS: policy = "always"; break; | |
e2641e09 | 820 | default: policy = "unknown"; break; /* too harmless to panic */ |
821 | } | |
822 | addReplyBulkCString(c,"appendfsync"); | |
823 | addReplyBulkCString(c,policy); | |
824 | matches++; | |
825 | } | |
826 | if (stringmatch(pattern,"save",0)) { | |
827 | sds buf = sdsempty(); | |
828 | int j; | |
829 | ||
830 | for (j = 0; j < server.saveparamslen; j++) { | |
831 | buf = sdscatprintf(buf,"%ld %d", | |
832 | server.saveparams[j].seconds, | |
833 | server.saveparams[j].changes); | |
834 | if (j != server.saveparamslen-1) | |
835 | buf = sdscatlen(buf," ",1); | |
836 | } | |
837 | addReplyBulkCString(c,"save"); | |
838 | addReplyBulkCString(c,buf); | |
839 | sdsfree(buf); | |
840 | matches++; | |
841 | } | |
2aa26d2a | 842 | if (stringmatch(pattern,"loglevel",0)) { |
843 | char *s; | |
844 | ||
845 | switch(server.verbosity) { | |
846 | case REDIS_WARNING: s = "warning"; break; | |
847 | case REDIS_VERBOSE: s = "verbose"; break; | |
848 | case REDIS_NOTICE: s = "notice"; break; | |
849 | case REDIS_DEBUG: s = "debug"; break; | |
850 | default: s = "unknown"; break; /* too harmless to panic */ | |
851 | } | |
852 | addReplyBulkCString(c,"loglevel"); | |
853 | addReplyBulkCString(c,s); | |
854 | matches++; | |
855 | } | |
7fe8d49a | 856 | if (stringmatch(pattern,"client-output-buffer-limit",0)) { |
857 | sds buf = sdsempty(); | |
858 | int j; | |
859 | ||
860 | for (j = 0; j < REDIS_CLIENT_LIMIT_NUM_CLASSES; j++) { | |
861 | buf = sdscatprintf(buf,"%s %llu %llu %ld", | |
862 | getClientLimitClassName(j), | |
863 | server.client_obuf_limits[j].hard_limit_bytes, | |
864 | server.client_obuf_limits[j].soft_limit_bytes, | |
865 | (long) server.client_obuf_limits[j].soft_limit_seconds); | |
866 | if (j != REDIS_CLIENT_LIMIT_NUM_CLASSES-1) | |
867 | buf = sdscatlen(buf," ",1); | |
868 | } | |
869 | addReplyBulkCString(c,"client-output-buffer-limit"); | |
870 | addReplyBulkCString(c,buf); | |
871 | sdsfree(buf); | |
872 | matches++; | |
873 | } | |
0823e48f | 874 | if (stringmatch(pattern,"unixsocketperm",0)) { |
875 | char buf[32]; | |
876 | snprintf(buf,sizeof(buf),"%o",server.unixsocketperm); | |
877 | addReplyBulkCString(c,"unixsocketperm"); | |
878 | addReplyBulkCString(c,buf); | |
879 | matches++; | |
880 | } | |
881 | if (stringmatch(pattern,"slaveof",0)) { | |
882 | char buf[256]; | |
883 | ||
884 | addReplyBulkCString(c,"slaveof"); | |
885 | if (server.masterhost) | |
886 | snprintf(buf,sizeof(buf),"%s %d", | |
887 | server.masterhost, server.masterport); | |
888 | else | |
889 | buf[0] = '\0'; | |
890 | addReplyBulkCString(c,buf); | |
4d3bbf35 | 891 | matches++; |
892 | } | |
b301c1fc | 893 | setDeferredMultiBulkLength(c,replylen,matches*2); |
e2641e09 | 894 | } |
895 | ||
896 | void configCommand(redisClient *c) { | |
897 | if (!strcasecmp(c->argv[1]->ptr,"set")) { | |
898 | if (c->argc != 4) goto badarity; | |
899 | configSetCommand(c); | |
900 | } else if (!strcasecmp(c->argv[1]->ptr,"get")) { | |
901 | if (c->argc != 3) goto badarity; | |
902 | configGetCommand(c); | |
903 | } else if (!strcasecmp(c->argv[1]->ptr,"resetstat")) { | |
904 | if (c->argc != 2) goto badarity; | |
9f8ded8c | 905 | server.stat_keyspace_hits = 0; |
906 | server.stat_keyspace_misses = 0; | |
e2641e09 | 907 | server.stat_numcommands = 0; |
908 | server.stat_numconnections = 0; | |
909 | server.stat_expiredkeys = 0; | |
ca09ad4d | 910 | server.stat_rejected_conn = 0; |
911 | server.stat_fork_time = 0; | |
c1d01b3c | 912 | server.aof_delayed_fsync = 0; |
d7ed7fd2 | 913 | resetCommandTableStats(); |
e2641e09 | 914 | addReply(c,shared.ok); |
915 | } else { | |
3ab20376 PN |
916 | addReplyError(c, |
917 | "CONFIG subcommand must be one of GET, SET, RESETSTAT"); | |
e2641e09 | 918 | } |
919 | return; | |
920 | ||
921 | badarity: | |
3ab20376 PN |
922 | addReplyErrorFormat(c,"Wrong number of arguments for CONFIG %s", |
923 | (char*) c->argv[1]->ptr); | |
e2641e09 | 924 | } |