From 5f5b7f1ac70c840ec1cd7fffcecb0654e9878be6 Mon Sep 17 00:00:00 2001 From: siddontang Date: Wed, 27 Aug 2014 10:57:18 +0800 Subject: [PATCH] add flush command complete client command and document --- client/ledis-py/ledis/client.py | 28 ++++++++++++++++++++++++++- client/nodejs/ledis/lib/commands.js | 12 +++++++++--- client/openresty/ledis.lua | 9 +++++++++ doc/commands.json | 28 ++++++++++++++++++++++----- doc/commands.md | 30 +++++++++++++++++++++++++++++ server/client.go | 2 ++ server/command.go | 23 +++++++++++++++++++++- 7 files changed, 122 insertions(+), 10 deletions(-) diff --git a/client/ledis-py/ledis/client.py b/client/ledis-py/ledis/client.py index de3dd2d..a083ca6 100644 --- a/client/ledis-py/ledis/client.py +++ b/client/ledis-py/ledis/client.py @@ -95,7 +95,7 @@ class Ledis(object): lambda r: isinstance(r, long) and r or nativestr(r) == 'OK' ), string_keys_to_dict( - 'MSET SELECT ', + 'MSET SELECT', lambda r: nativestr(r) == 'OK' ), string_keys_to_dict( @@ -219,6 +219,16 @@ class Ledis(object): db = 0 return self.execute_command('SELECT', db) + def info(self, section): + return self.execute_command('PING', section) + + def flushall(self): + return self.execute_command('FLUSHALL') + + def flushdb(self): + return self.execute_command('FLUSHDB') + + #### BASIC KEY COMMANDS #### def decr(self, name, amount=1): """ @@ -340,6 +350,9 @@ class Ledis(object): "Removes an expiration on name" return self.execute_command('PERSIST', name) + def scan(self, key, match = "", count = 10): + return self.execute_command("SCAN", key, match, count) + #### LIST COMMANDS #### def lindex(self, name, index): """ @@ -415,6 +428,9 @@ class Ledis(object): "Removes an expiration on ``name``" return self.execute_command('LPERSIST', name) + def lscan(self, key, match = "", count = 10): + return self.execute_command("LSCAN", key, match, count) + #### SET COMMANDS #### def sadd(self, name, *values): @@ -512,6 +528,9 @@ class Ledis(object): "Removes an expiration on name" return self.execute_command('SPERSIST', name) + def sscan(self, key, match = "", count = 10): + return self.execute_command("SSCAN", key, match, count) + #### SORTED SET COMMANDS #### def zadd(self, name, *args, **kwargs): @@ -708,6 +727,8 @@ class Ledis(object): "Removes an expiration on name" return self.execute_command('ZPERSIST', name) + def zscan(self, key, match = "", count = 10): + return self.execute_command("ZSCAN", key, match, count) #### HASH COMMANDS #### @@ -802,6 +823,9 @@ class Ledis(object): "Removes an expiration on name" return self.execute_command('HPERSIST', name) + def hscan(self, key, match = "", count = 10): + return self.execute_command("HSCAN", key, match, count) + ### BIT COMMANDS def bget(self, name): @@ -878,6 +902,8 @@ class Ledis(object): "Removes an expiration on name" return self.execute_command('BPERSIST', name) + def bscan(self, key, match = "", count = 10): + return self.execute_command("BSCAN", key, match, count) class Transaction(Ledis): def __init__(self, connection_pool, response_callbacks): diff --git a/client/nodejs/ledis/lib/commands.js b/client/nodejs/ledis/lib/commands.js index 8a53ca2..696bc7e 100644 --- a/client/nodejs/ledis/lib/commands.js +++ b/client/nodejs/ledis/lib/commands.js @@ -5,6 +5,9 @@ module.exports = [ "ping", "echo", "select", + "info", + "flushall", + "flushdb", "bget", "bdelete", @@ -17,7 +20,7 @@ module.exports = [ "bexpireat", "bttl", "bpersist", - + "bscan", "hdel", "hexists", @@ -31,14 +34,13 @@ module.exports = [ "hset", "hvals", - "hclear", "hmclear", "hexpire", "hexpireat", "httl", "hpersist", - + "hscan", "decr", "decrby", @@ -56,6 +58,7 @@ module.exports = [ "expireat", "ttl", "persist", + "scan", "lindex", "llen", @@ -72,6 +75,7 @@ module.exports = [ "lexpireat", "lttl", "lpersist", + "lscan", "zadd", "zcard", @@ -97,6 +101,7 @@ module.exports = [ "zexpireat", "zttl", "zpersist", + "zscan", "sadd", @@ -118,6 +123,7 @@ module.exports = [ "sexpireat", "sttl", "spersist", + "sscan", "begin", "rollback", diff --git a/client/openresty/ledis.lua b/client/openresty/ledis.lua index 3bb0d02..a25319e 100644 --- a/client/openresty/ledis.lua +++ b/client/openresty/ledis.lua @@ -40,6 +40,7 @@ local commands = { "expire", "expireat", "persist", + "scan", --[[hash]] "hdel", @@ -60,6 +61,7 @@ local commands = { "hexpireat", "httl", "hpersist", + "hscan", --[[list]] "lindex", @@ -76,6 +78,7 @@ local commands = { "lexpireat", "lttl", "lpersist", + "lscan", --[[zset]] "zadd", @@ -99,6 +102,7 @@ local commands = { "zexpireat", "zttl", "zpersist", + "zscan", --[[bit]] "bget", @@ -112,6 +116,7 @@ local commands = { "bexpireat", "bttl", "bpersist", + "bscan", --[[set]] "sadd", @@ -133,11 +138,15 @@ local commands = { "sexpireat", "sttl", "spersist", + "sscan", --[[server]] "ping", "echo", "select", + "info", + "flushall", + "flushdb", -- [[transaction]] "begin", diff --git a/doc/commands.json b/doc/commands.json index 817f252..e6ad2e2 100644 --- a/doc/commands.json +++ b/doc/commands.json @@ -531,36 +531,54 @@ "SCAN": { "arguments": "key [MATCH match] [COUNT count]", "group": "KV", - "readonly": false + "readonly": true }, "HSCAN": { "arguments": "key [MATCH match] [COUNT count]", "group": "Hash", - "readonly": false + "readonly": true }, "LSCAN": { "arguments": "key [MATCH match] [COUNT count]", "group": "List", - "readonly": false + "readonly": true }, "SSCAN": { "arguments": "key [MATCH match] [COUNT count]", "group": "Set", - "readonly": false + "readonly": true }, "ZSCAN": { "arguments": "key [MATCH match] [COUNT count]", "group": "ZSet", - "readonly": false + "readonly": true }, "BSCAN": { "arguments": "key [MATCH match] [COUNT count]", "group": "Bitmap", + "readonly": true + }, + + "FLUSHALL": { + "arguments": "-", + "group": "Server", "readonly": false + }, + + "FLUSHDB": { + "arguments": "-", + "group": "Server", + "readonly": false + }, + + "INFO": { + "arguments": "[section]", + "group": "Server", + "readonly": true } } diff --git a/doc/commands.md b/doc/commands.md index d7f1fab..535602d 100644 --- a/doc/commands.md +++ b/doc/commands.md @@ -126,6 +126,9 @@ Table of Contents - [PING](#ping) - [ECHO message](#echo-message) - [SELECT index](#select-index) + - [FLUSHALL](#flushall) + - [FLUSHDB](#flushdb) + - [INFO [section]](#info-section) - [Transaction](#transaction) - [BEGIN](#begin) - [ROLLBACK](#rollback) @@ -2468,6 +2471,33 @@ ledis> SELECT 16 ERR invalid db index 16 ``` +### FLUSHALL + +Delete all the keys of all the existing databases, not just the currently selected one. This command never fails. + +Very dangerous to use!!! + +### FLUSHDB + +Delete all the keys of the currently selected DB. This command never fails. + +Very dangerous to use!!! + +### INFO [section] + +Return information and statistic about the server in a format that is simple to parse by computers and easy to read by humans. + +The optional parameter can be used to select a specific section of information: + ++ server: General information about the Redis server ++ client: Client connections section ++ mem: Memory consumption related information ++ cpu: CPU consumption statistics ++ goroutine: Goroutine num ++ persistence: Strorage related information + +When no parameter is provided, all will return. + ## Transaction ### BEGIN diff --git a/server/client.go b/server/client.go index 7613562..f28a930 100644 --- a/server/client.go +++ b/server/client.go @@ -14,6 +14,8 @@ var txUnsupportedCmds = map[string]struct{}{ "fullsync": struct{}{}, "sync": struct{}{}, "begin": struct{}{}, + "flushall": struct{}{}, + "flushdb": struct{}{}, } type responseWriter interface { diff --git a/server/command.go b/server/command.go index 2bf86a5..af95244 100644 --- a/server/command.go +++ b/server/command.go @@ -67,10 +67,31 @@ func infoCommand(c *client) error { return nil } -func init() { +func flushallCommand(c *client) error { + err := c.ldb.FlushAll() + if err != nil { + return err + } + c.resp.writeStatus(OK) + return nil +} + +func flushdbCommand(c *client) error { + _, err := c.db.FlushAll() + if err != nil { + return err + } + + c.resp.writeStatus(OK) + return nil +} + +func init() { register("ping", pingCommand) register("echo", echoCommand) register("select", selectCommand) register("info", infoCommand) + register("flushall", flushallCommand) + register("flushdb", flushdbCommand) }