add key exists for hash, list, set and zset

This commit is contained in:
siddontang 2015-03-04 09:33:25 +08:00
parent c69f803f37
commit 71b32895b8
19 changed files with 90 additions and 41 deletions

View File

@ -1,4 +1,4 @@
//This file was generated by .tools/generate_commands.py on Wed Mar 04 2015 09:09:49 +0800
//This file was generated by .tools/generate_commands.py on Wed Mar 04 2015 09:31:59 +0800
package main
var helpCommands = [][]string{
@ -38,6 +38,7 @@ var helpCommands = [][]string{
{"HGET", "key field", "Hash"},
{"HGETALL", "key", "Hash"},
{"HINCRBY", "key field increment", "Hash"},
{"HKEYEXISTS", "key", "Hash"},
{"HKEYS", "key", "Hash"},
{"HLEN", "key", "Hash"},
{"HMCLEAR", "key [key ...]", "Hash"},
@ -55,6 +56,7 @@ var helpCommands = [][]string{
{"LEXPIRE", "key seconds", "List"},
{"LEXPIREAT", "key timestamp", "List"},
{"LINDEX", "key index", "List"},
{"LKEYEXISTS", "key", "List"},
{"LLEN", "key", "List"},
{"LMCLEAR", "key [key ...]", "List"},
{"LPERSIST", "key", "List"},
@ -91,6 +93,7 @@ var helpCommands = [][]string{
{"SINTER", "key [key ...]", "Set"},
{"SINTERSTORE", "destination key [key ...]", "Set"},
{"SISMEMBER", "key member", "Set"},
{"SKEYEXISTS", "key", "Set"},
{"SLAVEOF", "host port [RESTART] [READONLY]", "Replication"},
{"SMCLEAR", "key [key ...]", "Set"},
{"SMEMBERS", "key", "Set"},
@ -116,6 +119,7 @@ var helpCommands = [][]string{
{"ZEXPIREAT", "key timestamp", "ZSet"},
{"ZINCRBY", "key increment member", "ZSet"},
{"ZINTERSTORE", "destkey numkeys key [key ...] [WEIGHTS weight [weight ...]] [AGGREGATE SUM|MIN|MAX]", "ZSet"},
{"ZKEYEXISTS", "ZSet", "Hash"},
{"ZLEXCOUNT", "key min max", "ZSet"},
{"ZMCLEAR", "key [key ...]", "ZSet"},
{"ZPERSIST", "key", "ZSet"},

View File

@ -691,5 +691,29 @@
"arguments" : "key offset value",
"group" : "KV",
"readonly" : false
},
"HKEYEXISTS": {
"arguments" : "key",
"group" : "Hash",
"readonly" : true
},
"LKEYEXISTS": {
"arguments" : "key",
"group" : "List",
"readonly" : true
},
"SKEYEXISTS": {
"arguments" : "key",
"group" : "Set",
"readonly" : true
},
"ZKEYEXISTS": {
"arguments" : "ZSet",
"group" : "Hash",
"readonly" : true
}
}

View File

@ -57,6 +57,7 @@ Most of the Ledisdb's commands are the same as Redis's, you can see the redis co
- [HTTL key](#httl-key)
- [HPERSIST key](#hpersist-key)
- [HDUMP key](#hdump-key)
- [HKEYEXISTS key](#hkeyexists-key)
- [List](#list)
- [BLPOP key [key ...] timeout](#blpop-key-key--timeout)
- [BRPOP key [key ...] timeout](#brpop-key-key--timeout)
@ -74,6 +75,7 @@ Most of the Ledisdb's commands are the same as Redis's, you can see the redis co
- [LTTL key](#lttl-key)
- [LPERSIST key](#lpersist-key)
- [LDUMP key](#ldump-key)
- [LKEYEXISTS key](#lkeyexists-key)
- [Set](#set)
- [SADD key member [member ...]](#sadd-key-member-member-)
- [SCARD key](#scard-key)
@ -93,6 +95,7 @@ Most of the Ledisdb's commands are the same as Redis's, you can see the redis co
- [STTL key](#sttl-key)
- [SPERSIST key](#spersist-key)
- [SDUMP key](#sdump-key)
- [SKEYEXISTS key](#skeyexists-key)
- [ZSet](#zset)
- [ZADD key score member [score member ...]](#zadd-key-score-member-score-member-)
- [ZCARD key](#zcard-key)
@ -120,6 +123,7 @@ Most of the Ledisdb's commands are the same as Redis's, you can see the redis co
- [ZREMRANGEBYLEX key min max](#zremrangebylex-key-min-max)
- [ZLEXCOUNT key min max](#zlexcount-key-min-max)
- [ZDUMP key](#zdump-key)
- [ZKEYEXISTS key](#zkeyexists-key)
- [Scan](#scan)
- [XSCAN type cursor [MATCH match] [COUNT count]](#xscan-type-cursor-match-match-count-count)
- [XHSCAN key cursor [MATCH match] [COUNT count]](#xhscan-key-cursor-match-match-count-count)
@ -909,6 +913,10 @@ ledis> HPERSIST not_exists_key
See [DUMP](#dump-key) for more information.
### HKEYEXISTS key
Check key exists for hash data, like [EXISTS key](#exists-key)
## List
### BLPOP key [key ...] timeout
@ -1235,6 +1243,9 @@ ledis> LPERSIST b
See [DUMP](#dump-key) for more information.
### LKEYEXISTS key
Check key exists for list data, like [EXISTS key](#exists-key)
## Set
@ -1661,6 +1672,10 @@ ledis> STTL key
See [DUMP](#dump-key) for more information.
### SKEYEXISTS key
Check key exists for set data, like [EXISTS key](#exists-key)
## ZSet
### ZADD key score member [score member ...]
@ -2350,6 +2365,10 @@ ledis> ZLEXCOUNT myzset - [c
See [DUMP](#dump-key) for more information.
### ZKEYEXISTS key
Check key exists for zset data, like [EXISTS key](#exists-key)
## Scan
### XSCAN type cursor [MATCH match] [COUNT count]

View File

@ -502,7 +502,7 @@ func (db *DB) HPersist(key []byte) (int64, error) {
return n, err
}
func (db *DB) XHExists(key []byte) (int64, error) {
func (db *DB) HKeyExists(key []byte) (int64, error) {
if err := checkKeySize(key); err != nil {
return 0, err
}

View File

@ -79,10 +79,10 @@ func TestHashPersist(t *testing.T) {
t.Fatal(n)
}
}
func TestXHashExists(t *testing.T) {
func TestHashKeyExists(t *testing.T) {
db := getTestDB()
key := []byte("xhexists_test")
v, err := db.XHExists(key)
key := []byte("hkeyexists_test")
v, err := db.HKeyExists(key)
if err != nil {
t.Fatal(err.Error())
}
@ -94,7 +94,7 @@ func TestXHashExists(t *testing.T) {
t.Fatal(err.Error())
}
v, err = db.XHExists(key)
v, err = db.HKeyExists(key)
if err != nil {
t.Fatal(err.Error())
}

View File

@ -498,7 +498,7 @@ func (db *DB) BRPop(keys [][]byte, timeout time.Duration) ([]interface{}, error)
return db.lblockPop(keys, listTailSeq, timeout)
}
func (db *DB) XLExists(key []byte) (int64, error) {
func (db *DB) LKeyExists(key []byte) (int64, error) {
if err := checkKeySize(key); err != nil {
return 0, err
}

View File

@ -164,16 +164,16 @@ func TestLFlush(t *testing.T) {
}
}
func TestXLExists(t *testing.T) {
func TestLKeyExists(t *testing.T) {
db := getTestDB()
key := []byte("xlexists_test")
if n, err := db.XLExists(key); err != nil {
key := []byte("lkeyexists_test")
if n, err := db.LKeyExists(key); err != nil {
t.Fatal(err.Error())
} else if n != 0 {
t.Fatal("invalid value ", n)
}
db.LPush(key, []byte("hello"), []byte("world"))
if n, err := db.XLExists(key); err != nil {
if n, err := db.LKeyExists(key); err != nil {
t.Fatal(err.Error())
} else if n != 1 {
t.Fatal("invalid value ", n)

View File

@ -286,7 +286,7 @@ func (db *DB) SDiffStore(dstKey []byte, keys ...[]byte) (int64, error) {
return n, err
}
func (db *DB) XSExists(key []byte) (int64, error) {
func (db *DB) SKeyExists(key []byte) (int64, error) {
if err := checkKeySize(key); err != nil {
return 0, err
}

View File

@ -372,10 +372,10 @@ func TestSFlush(t *testing.T) {
}
func TestXSExists(t *testing.T) {
func TestSKeyExists(t *testing.T) {
db := getTestDB()
key := []byte("xsexists_test")
if n, err := db.XSExists(key); err != nil {
key := []byte("skeyexists_test")
if n, err := db.SKeyExists(key); err != nil {
t.Fatal(err.Error())
} else if n != 0 {
t.Fatal("invalid value ", n)
@ -383,7 +383,7 @@ func TestXSExists(t *testing.T) {
db.SAdd(key, []byte("hello"), []byte("world"))
if n, err := db.XSExists(key); err != nil {
if n, err := db.SKeyExists(key); err != nil {
t.Fatal(err.Error())
} else if n != 1 {
t.Fatal("invalid value ", n)

View File

@ -1016,7 +1016,7 @@ func (db *DB) ZLexCount(key []byte, min []byte, max []byte, rangeType uint8) (in
return n, nil
}
func (db *DB) XZExists(key []byte) (int64, error) {
func (db *DB) ZKeyExists(key []byte) (int64, error) {
if err := checkKeySize(key); err != nil {
return 0, err
}

View File

@ -466,10 +466,10 @@ func TestZLex(t *testing.T) {
}
func TestXZExists(t *testing.T) {
func TestZKeyExists(t *testing.T) {
db := getTestDB()
key := []byte("xzexists_test")
if n, err := db.XZExists(key); err != nil {
key := []byte("zkeyexists_test")
if n, err := db.ZKeyExists(key); err != nil {
t.Fatal(err.Error())
} else if n != 0 {
t.Fatal("invalid value ", n)
@ -477,7 +477,7 @@ func TestXZExists(t *testing.T) {
db.ZAdd(key, ScorePair{0, []byte("a")}, ScorePair{0, []byte("b")})
if n, err := db.XZExists(key); err != nil {
if n, err := db.ZKeyExists(key); err != nil {
t.Fatal(err.Error())
} else if n != 1 {
t.Fatal("invalid value ", n)

View File

@ -292,12 +292,12 @@ func hpersistCommand(c *client) error {
return nil
}
func xhexistsCommand(c *client) error {
func hkeyexistsCommand(c *client) error {
args := c.args
if len(args) != 1 {
return ErrCmdParams
}
if n, err := c.db.XHExists(args[0]); err != nil {
if n, err := c.db.HKeyExists(args[0]); err != nil {
return err
} else {
c.resp.writeInteger(n)
@ -326,5 +326,5 @@ func init() {
register("hexpireat", hexpireAtCommand)
register("httl", httlCommand)
register("hpersist", hpersistCommand)
register("xhexists", xhexistsCommand)
register("hkeyexists", hkeyexistsCommand)
}

View File

@ -12,7 +12,7 @@ func TestHash(t *testing.T) {
defer c.Close()
key := []byte("a")
if n, err := ledis.Int(c.Do("xhexists", key)); err != nil {
if n, err := ledis.Int(c.Do("hkeyexists", key)); err != nil {
t.Fatal(err)
} else if n != 0 {
t.Fatal(n)
@ -23,7 +23,7 @@ func TestHash(t *testing.T) {
} else if n != 1 {
t.Fatal(n)
}
if n, err := ledis.Int(c.Do("xhexists", key)); err != nil {
if n, err := ledis.Int(c.Do("hkeyexists", key)); err != nil {
t.Fatal(err)
} else if n != 1 {
t.Fatal(n)

View File

@ -277,12 +277,13 @@ func lParseBPopArgs(c *client) (keys [][]byte, timeout time.Duration, err error)
keys = args[0 : len(args)-1]
return
}
func xlexistsCommand(c *client) error {
func lkeyexistsCommand(c *client) error {
args := c.args
if len(args) != 1 {
return ErrCmdParams
}
if n, err := c.db.XLExists(args[0]); err != nil {
if n, err := c.db.LKeyExists(args[0]); err != nil {
return err
} else {
c.resp.writeInteger(n)
@ -309,5 +310,5 @@ func init() {
register("lexpireat", lexpireAtCommand)
register("lttl", lttlCommand)
register("lpersist", lpersistCommand)
register("xlexists", xlexistsCommand)
register("lkeyexists", lkeyexistsCommand)
}

View File

@ -58,7 +58,7 @@ func TestList(t *testing.T) {
defer c.Close()
key := []byte("a")
if n, err := ledis.Int(c.Do("xlexists", key)); err != nil {
if n, err := ledis.Int(c.Do("lkeyexists", key)); err != nil {
t.Fatal(err)
} else if n != 0 {
t.Fatal(n)
@ -70,7 +70,7 @@ func TestList(t *testing.T) {
t.Fatal(n)
}
if n, err := ledis.Int(c.Do("xlexists", key)); err != nil {
if n, err := ledis.Int(c.Do("lkeyexists", key)); err != nil {
t.Fatal(err)
} else if n != 1 {
t.Fatal(1)

View File

@ -262,12 +262,12 @@ func spersistCommand(c *client) error {
return nil
}
func xsexistsCommand(c *client) error {
func skeyexistsCommand(c *client) error {
args := c.args
if len(args) != 1 {
return ErrCmdParams
}
if n, err := c.db.XSExists(args[0]); err != nil {
if n, err := c.db.SKeyExists(args[0]); err != nil {
return err
} else {
c.resp.writeInteger(n)
@ -287,12 +287,13 @@ func init() {
register("srem", sremCommand)
register("sunion", sunionCommand)
register("sunionstore", sunionstoreCommand)
register("sclear", sclearCommand)
register("smclear", smclearCommand)
register("sexpire", sexpireCommand)
register("sexpireat", sexpireAtCommand)
register("sttl", sttlCommand)
register("spersist", spersistCommand)
register("xsexists", xsexistsCommand)
register("skeyexists", skeyexistsCommand)
}

View File

@ -12,7 +12,7 @@ func TestSet(t *testing.T) {
key1 := "testdb_cmd_set_1"
key2 := "testdb_cmd_set_2"
if n, err := ledis.Int(c.Do("xsexists", key1)); err != nil {
if n, err := ledis.Int(c.Do("skeyexists", key1)); err != nil {
t.Fatal(err)
} else if n != 0 {
t.Fatal(n)
@ -24,7 +24,7 @@ func TestSet(t *testing.T) {
t.Fatal(n)
}
if n, err := ledis.Int(c.Do("xsexists", key1)); err != nil {
if n, err := ledis.Int(c.Do("skeyexists", key1)); err != nil {
t.Fatal(err)
} else if n != 1 {
t.Fatal(n)

View File

@ -763,12 +763,12 @@ func zlexcountCommand(c *client) error {
return nil
}
func xzexistsCommand(c *client) error {
func zkeyexistsCommand(c *client) error {
args := c.args
if len(args) != 1 {
return ErrCmdParams
}
if n, err := c.db.XZExists(args[0]); err != nil {
if n, err := c.db.ZKeyExists(args[0]); err != nil {
return err
} else {
c.resp.writeInteger(n)
@ -807,5 +807,5 @@ func init() {
register("zexpireat", zexpireAtCommand)
register("zttl", zttlCommand)
register("zpersist", zpersistCommand)
register("xzexists", xzexistsCommand)
register("zkeyexists", zkeyexistsCommand)
}

View File

@ -14,7 +14,7 @@ func TestZSet(t *testing.T) {
key := []byte("myzset")
if n, err := ledis.Int(c.Do("xzexists", key)); err != nil {
if n, err := ledis.Int(c.Do("zkeyexists", key)); err != nil {
t.Fatal(err)
} else if n != 0 {
t.Fatal(n)
@ -26,7 +26,7 @@ func TestZSet(t *testing.T) {
t.Fatal(n)
}
if n, err := ledis.Int(c.Do("xzexists", key)); err != nil {
if n, err := ledis.Int(c.Do("zkeyexists", key)); err != nil {
t.Fatal(err)
} else if n != 1 {
t.Fatal(n)