diff --git a/cmd/ledis-cli/const.go b/cmd/ledis-cli/const.go index 4bba07f..df18fd6 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 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"}, diff --git a/doc/commands.json b/doc/commands.json index 181ce7b..1ae730a 100644 --- a/doc/commands.json +++ b/doc/commands.json @@ -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 } } diff --git a/doc/commands.md b/doc/commands.md index c76447a..a5f33d7 100644 --- a/doc/commands.md +++ b/doc/commands.md @@ -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] diff --git a/ledis/t_hash.go b/ledis/t_hash.go index c7b92dd..cd158cb 100644 --- a/ledis/t_hash.go +++ b/ledis/t_hash.go @@ -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 } diff --git a/ledis/t_hash_test.go b/ledis/t_hash_test.go index 6afa2da..52452ca 100644 --- a/ledis/t_hash_test.go +++ b/ledis/t_hash_test.go @@ -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()) } diff --git a/ledis/t_list.go b/ledis/t_list.go index c2cc5a9..f5756b2 100644 --- a/ledis/t_list.go +++ b/ledis/t_list.go @@ -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 } diff --git a/ledis/t_list_test.go b/ledis/t_list_test.go index 58c1c58..2311759 100644 --- a/ledis/t_list_test.go +++ b/ledis/t_list_test.go @@ -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) diff --git a/ledis/t_set.go b/ledis/t_set.go index 200d66b..3980768 100644 --- a/ledis/t_set.go +++ b/ledis/t_set.go @@ -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 } diff --git a/ledis/t_set_test.go b/ledis/t_set_test.go index b6b1460..c67ce32 100644 --- a/ledis/t_set_test.go +++ b/ledis/t_set_test.go @@ -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) diff --git a/ledis/t_zset.go b/ledis/t_zset.go index 0bd22a3..e33344a 100644 --- a/ledis/t_zset.go +++ b/ledis/t_zset.go @@ -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 } diff --git a/ledis/t_zset_test.go b/ledis/t_zset_test.go index 6323091..f2bc7ee 100644 --- a/ledis/t_zset_test.go +++ b/ledis/t_zset_test.go @@ -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) diff --git a/server/cmd_hash.go b/server/cmd_hash.go index b9acc85..77b1f40 100644 --- a/server/cmd_hash.go +++ b/server/cmd_hash.go @@ -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) } diff --git a/server/cmd_hash_test.go b/server/cmd_hash_test.go index dbf03db..c9bbd77 100644 --- a/server/cmd_hash_test.go +++ b/server/cmd_hash_test.go @@ -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) diff --git a/server/cmd_list.go b/server/cmd_list.go index d3ac6e2..3d96a4c 100644 --- a/server/cmd_list.go +++ b/server/cmd_list.go @@ -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) } diff --git a/server/cmd_list_test.go b/server/cmd_list_test.go index cb5a1e0..5a237fc 100644 --- a/server/cmd_list_test.go +++ b/server/cmd_list_test.go @@ -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) diff --git a/server/cmd_set.go b/server/cmd_set.go index b2ee2dc..4b780b7 100644 --- a/server/cmd_set.go +++ b/server/cmd_set.go @@ -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) } diff --git a/server/cmd_set_test.go b/server/cmd_set_test.go index 83b44e9..2680c81 100644 --- a/server/cmd_set_test.go +++ b/server/cmd_set_test.go @@ -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) diff --git a/server/cmd_zset.go b/server/cmd_zset.go index 77d2db3..9c6fdac 100644 --- a/server/cmd_zset.go +++ b/server/cmd_zset.go @@ -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) } diff --git a/server/cmd_zset_test.go b/server/cmd_zset_test.go index fa5224d..fbb9a80 100644 --- a/server/cmd_zset_test.go +++ b/server/cmd_zset_test.go @@ -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)