add flush command

complete client command and document
This commit is contained in:
siddontang 2014-08-27 10:57:18 +08:00
parent fa6adeabee
commit 5f5b7f1ac7
7 changed files with 122 additions and 10 deletions

View File

@ -219,6 +219,16 @@ class Ledis(object):
db = 0 db = 0
return self.execute_command('SELECT', db) 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 #### #### BASIC KEY COMMANDS ####
def decr(self, name, amount=1): def decr(self, name, amount=1):
""" """
@ -340,6 +350,9 @@ class Ledis(object):
"Removes an expiration on name" "Removes an expiration on name"
return self.execute_command('PERSIST', name) return self.execute_command('PERSIST', name)
def scan(self, key, match = "", count = 10):
return self.execute_command("SCAN", key, match, count)
#### LIST COMMANDS #### #### LIST COMMANDS ####
def lindex(self, name, index): def lindex(self, name, index):
""" """
@ -415,6 +428,9 @@ class Ledis(object):
"Removes an expiration on ``name``" "Removes an expiration on ``name``"
return self.execute_command('LPERSIST', name) return self.execute_command('LPERSIST', name)
def lscan(self, key, match = "", count = 10):
return self.execute_command("LSCAN", key, match, count)
#### SET COMMANDS #### #### SET COMMANDS ####
def sadd(self, name, *values): def sadd(self, name, *values):
@ -512,6 +528,9 @@ class Ledis(object):
"Removes an expiration on name" "Removes an expiration on name"
return self.execute_command('SPERSIST', 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 #### #### SORTED SET COMMANDS ####
def zadd(self, name, *args, **kwargs): def zadd(self, name, *args, **kwargs):
@ -708,6 +727,8 @@ class Ledis(object):
"Removes an expiration on name" "Removes an expiration on name"
return self.execute_command('ZPERSIST', name) return self.execute_command('ZPERSIST', name)
def zscan(self, key, match = "", count = 10):
return self.execute_command("ZSCAN", key, match, count)
#### HASH COMMANDS #### #### HASH COMMANDS ####
@ -802,6 +823,9 @@ class Ledis(object):
"Removes an expiration on name" "Removes an expiration on name"
return self.execute_command('HPERSIST', name) return self.execute_command('HPERSIST', name)
def hscan(self, key, match = "", count = 10):
return self.execute_command("HSCAN", key, match, count)
### BIT COMMANDS ### BIT COMMANDS
def bget(self, name): def bget(self, name):
@ -878,6 +902,8 @@ class Ledis(object):
"Removes an expiration on name" "Removes an expiration on name"
return self.execute_command('BPERSIST', 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): class Transaction(Ledis):
def __init__(self, connection_pool, response_callbacks): def __init__(self, connection_pool, response_callbacks):

View File

@ -5,6 +5,9 @@ module.exports = [
"ping", "ping",
"echo", "echo",
"select", "select",
"info",
"flushall",
"flushdb",
"bget", "bget",
"bdelete", "bdelete",
@ -17,7 +20,7 @@ module.exports = [
"bexpireat", "bexpireat",
"bttl", "bttl",
"bpersist", "bpersist",
"bscan",
"hdel", "hdel",
"hexists", "hexists",
@ -31,14 +34,13 @@ module.exports = [
"hset", "hset",
"hvals", "hvals",
"hclear", "hclear",
"hmclear", "hmclear",
"hexpire", "hexpire",
"hexpireat", "hexpireat",
"httl", "httl",
"hpersist", "hpersist",
"hscan",
"decr", "decr",
"decrby", "decrby",
@ -56,6 +58,7 @@ module.exports = [
"expireat", "expireat",
"ttl", "ttl",
"persist", "persist",
"scan",
"lindex", "lindex",
"llen", "llen",
@ -72,6 +75,7 @@ module.exports = [
"lexpireat", "lexpireat",
"lttl", "lttl",
"lpersist", "lpersist",
"lscan",
"zadd", "zadd",
"zcard", "zcard",
@ -97,6 +101,7 @@ module.exports = [
"zexpireat", "zexpireat",
"zttl", "zttl",
"zpersist", "zpersist",
"zscan",
"sadd", "sadd",
@ -118,6 +123,7 @@ module.exports = [
"sexpireat", "sexpireat",
"sttl", "sttl",
"spersist", "spersist",
"sscan",
"begin", "begin",
"rollback", "rollback",

View File

@ -40,6 +40,7 @@ local commands = {
"expire", "expire",
"expireat", "expireat",
"persist", "persist",
"scan",
--[[hash]] --[[hash]]
"hdel", "hdel",
@ -60,6 +61,7 @@ local commands = {
"hexpireat", "hexpireat",
"httl", "httl",
"hpersist", "hpersist",
"hscan",
--[[list]] --[[list]]
"lindex", "lindex",
@ -76,6 +78,7 @@ local commands = {
"lexpireat", "lexpireat",
"lttl", "lttl",
"lpersist", "lpersist",
"lscan",
--[[zset]] --[[zset]]
"zadd", "zadd",
@ -99,6 +102,7 @@ local commands = {
"zexpireat", "zexpireat",
"zttl", "zttl",
"zpersist", "zpersist",
"zscan",
--[[bit]] --[[bit]]
"bget", "bget",
@ -112,6 +116,7 @@ local commands = {
"bexpireat", "bexpireat",
"bttl", "bttl",
"bpersist", "bpersist",
"bscan",
--[[set]] --[[set]]
"sadd", "sadd",
@ -133,11 +138,15 @@ local commands = {
"sexpireat", "sexpireat",
"sttl", "sttl",
"spersist", "spersist",
"sscan",
--[[server]] --[[server]]
"ping", "ping",
"echo", "echo",
"select", "select",
"info",
"flushall",
"flushdb",
-- [[transaction]] -- [[transaction]]
"begin", "begin",

View File

@ -531,36 +531,54 @@
"SCAN": { "SCAN": {
"arguments": "key [MATCH match] [COUNT count]", "arguments": "key [MATCH match] [COUNT count]",
"group": "KV", "group": "KV",
"readonly": false "readonly": true
}, },
"HSCAN": { "HSCAN": {
"arguments": "key [MATCH match] [COUNT count]", "arguments": "key [MATCH match] [COUNT count]",
"group": "Hash", "group": "Hash",
"readonly": false "readonly": true
}, },
"LSCAN": { "LSCAN": {
"arguments": "key [MATCH match] [COUNT count]", "arguments": "key [MATCH match] [COUNT count]",
"group": "List", "group": "List",
"readonly": false "readonly": true
}, },
"SSCAN": { "SSCAN": {
"arguments": "key [MATCH match] [COUNT count]", "arguments": "key [MATCH match] [COUNT count]",
"group": "Set", "group": "Set",
"readonly": false "readonly": true
}, },
"ZSCAN": { "ZSCAN": {
"arguments": "key [MATCH match] [COUNT count]", "arguments": "key [MATCH match] [COUNT count]",
"group": "ZSet", "group": "ZSet",
"readonly": false "readonly": true
}, },
"BSCAN": { "BSCAN": {
"arguments": "key [MATCH match] [COUNT count]", "arguments": "key [MATCH match] [COUNT count]",
"group": "Bitmap", "group": "Bitmap",
"readonly": true
},
"FLUSHALL": {
"arguments": "-",
"group": "Server",
"readonly": false "readonly": false
},
"FLUSHDB": {
"arguments": "-",
"group": "Server",
"readonly": false
},
"INFO": {
"arguments": "[section]",
"group": "Server",
"readonly": true
} }
} }

View File

@ -126,6 +126,9 @@ Table of Contents
- [PING](#ping) - [PING](#ping)
- [ECHO message](#echo-message) - [ECHO message](#echo-message)
- [SELECT index](#select-index) - [SELECT index](#select-index)
- [FLUSHALL](#flushall)
- [FLUSHDB](#flushdb)
- [INFO [section]](#info-section)
- [Transaction](#transaction) - [Transaction](#transaction)
- [BEGIN](#begin) - [BEGIN](#begin)
- [ROLLBACK](#rollback) - [ROLLBACK](#rollback)
@ -2468,6 +2471,33 @@ ledis> SELECT 16
ERR invalid db index 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 ## Transaction
### BEGIN ### BEGIN

View File

@ -14,6 +14,8 @@ var txUnsupportedCmds = map[string]struct{}{
"fullsync": struct{}{}, "fullsync": struct{}{},
"sync": struct{}{}, "sync": struct{}{},
"begin": struct{}{}, "begin": struct{}{},
"flushall": struct{}{},
"flushdb": struct{}{},
} }
type responseWriter interface { type responseWriter interface {

View File

@ -67,10 +67,31 @@ func infoCommand(c *client) error {
return nil 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("ping", pingCommand)
register("echo", echoCommand) register("echo", echoCommand)
register("select", selectCommand) register("select", selectCommand)
register("info", infoCommand) register("info", infoCommand)
register("flushall", flushallCommand)
register("flushdb", flushdbCommand)
} }