From 53f89f671b771ebd7af99c1b932aca619032ad90 Mon Sep 17 00:00:00 2001 From: siddontang Date: Wed, 8 Oct 2014 16:39:14 +0800 Subject: [PATCH] add config rewrite command --- client/nodejs/ledis/lib/commands.js | 1 + client/openresty/ledis.lua | 1 + cmd/ledis-cli/const.go | 3 ++- doc/commands.json | 6 ++++++ doc/commands.md | 11 +++++++++++ server/cmd_server.go | 19 +++++++++++++++++++ 6 files changed, 40 insertions(+), 1 deletion(-) diff --git a/client/nodejs/ledis/lib/commands.js b/client/nodejs/ledis/lib/commands.js index 5ff7868..f9c4d6c 100644 --- a/client/nodejs/ledis/lib/commands.js +++ b/client/nodejs/ledis/lib/commands.js @@ -9,6 +9,7 @@ module.exports = [ "flushall", "flushdb", "time", + "config", "bget", "bdelete", diff --git a/client/openresty/ledis.lua b/client/openresty/ledis.lua index e00d1d7..ddbb150 100644 --- a/client/openresty/ledis.lua +++ b/client/openresty/ledis.lua @@ -154,6 +154,7 @@ local commands = { "flushall", "flushdb", "time", + "config", -- [[transaction]] "begin", diff --git a/cmd/ledis-cli/const.go b/cmd/ledis-cli/const.go index 4d9bb6a..f03b249 100644 --- a/cmd/ledis-cli/const.go +++ b/cmd/ledis-cli/const.go @@ -1,4 +1,4 @@ -//This file was generated by .tools/generate_commands.py on Wed Oct 08 2014 13:52:31 +0800 +//This file was generated by .tools/generate_commands.py on Wed Oct 08 2014 16:36:20 +0800 package main var helpCommands = [][]string{ @@ -16,6 +16,7 @@ var helpCommands = [][]string{ {"BTTL", "key", "Bitmap"}, {"BXSCAN", "key [MATCH match] [COUNT count]", "Bitmap"}, {"COMMIT", "-", "Transaction"}, + {"CONFIG REWRITE", "-", "Server"}, {"DECR", "key", "KV"}, {"DECRBY", "key decrement", "KV"}, {"DEL", "key [key ...]", "KV"}, diff --git a/doc/commands.json b/doc/commands.json index 3491c3c..8268ee8 100644 --- a/doc/commands.json +++ b/doc/commands.json @@ -634,5 +634,11 @@ "arguments" : "-", "group": "Server", "readonly": true + }, + + "CONFIG REWRITE": { + "arguments" : "-", + "group": "Server", + "readonly": false } } diff --git a/doc/commands.md b/doc/commands.md index b71fc9b..c01b67c 100644 --- a/doc/commands.md +++ b/doc/commands.md @@ -133,6 +133,7 @@ Table of Contents - [FLUSHDB](#flushdb) - [INFO [section]](#info-section) - [TIME](#time) + - [CONFIG REWRITE](#config-rewrite) - [Transaction](#transaction) - [BEGIN](#begin) - [ROLLBACK](#rollback) @@ -2579,6 +2580,16 @@ The TIME command returns the current server time as a two items lists: a Unix ti array: two elements, one is unix time in seconds, the other is microseconds. +### CONFIG REWRITE + +Rewrites the config file the server was started with. + +**Unlike Redis rewrite, it will discard all comments in origin config file.** + +**Return value** + +String: OK or error msg. + ## Transaction ### BEGIN diff --git a/server/cmd_server.go b/server/cmd_server.go index 38e96dd..d71da77 100644 --- a/server/cmd_server.go +++ b/server/cmd_server.go @@ -111,6 +111,24 @@ func timeCommand(c *client) error { return nil } +func configCommand(c *client) error { + if len(c.args) < 1 { + return ErrCmdParams + } + + switch strings.ToLower(hack.String(c.args[0])) { + case "rewrite": + if err := c.app.cfg.Rewrite(); err != nil { + return err + } else { + c.resp.writeStatus(OK) + return nil + } + default: + return ErrCmdParams + } +} + func init() { register("ping", pingCommand) register("echo", echoCommand) @@ -119,4 +137,5 @@ func init() { register("flushall", flushallCommand) register("flushdb", flushdbCommand) register("time", timeCommand) + register("config", configCommand) }