From 31e70ccd022f69bafa49c992b59189ce8c64ea9c Mon Sep 17 00:00:00 2001 From: siddontang Date: Tue, 24 Jun 2014 12:44:44 +0800 Subject: [PATCH] add persist command --- server/cmd_hash.go | 16 ++++++++++++++++ server/cmd_kv.go | 16 ++++++++++++++++ server/cmd_list.go | 16 ++++++++++++++++ server/cmd_ttl_test.go | 18 ++++++++++++++++++ server/cmd_zset.go | 16 ++++++++++++++++ 5 files changed, 82 insertions(+) diff --git a/server/cmd_hash.go b/server/cmd_hash.go index 1dd36e0..3311c8c 100644 --- a/server/cmd_hash.go +++ b/server/cmd_hash.go @@ -262,6 +262,21 @@ func httlCommand(c *client) error { return nil } +func hpersistCommand(c *client) error { + args := c.args + if len(args) != 1 { + return ErrCmdParams + } + + if n, err := c.db.HPersist(args[0]); err != nil { + return err + } else { + c.writeInteger(n) + } + + return nil +} + func init() { register("hdel", hdelCommand) register("hexists", hexistsCommand) @@ -281,4 +296,5 @@ func init() { register("hexpire", hexpireCommand) register("hexpireat", hexpireAtCommand) register("httl", httlCommand) + register("hpersist", hpersistCommand) } diff --git a/server/cmd_kv.go b/server/cmd_kv.go index d924e4e..9f72b39 100644 --- a/server/cmd_kv.go +++ b/server/cmd_kv.go @@ -258,6 +258,21 @@ func ttlCommand(c *client) error { return nil } +func persistCommand(c *client) error { + args := c.args + if len(args) != 1 { + return ErrCmdParams + } + + if n, err := c.db.Persist(args[0]); err != nil { + return err + } else { + c.writeInteger(n) + } + + return nil +} + // func (db *DB) Expire(key []byte, duration int6 // func (db *DB) ExpireAt(key []byte, when int64) // func (db *DB) TTL(key []byte) (int64, error) @@ -278,4 +293,5 @@ func init() { register("expire", expireCommand) register("expireat", expireAtCommand) register("ttl", ttlCommand) + register("persist", persistCommand) } diff --git a/server/cmd_list.go b/server/cmd_list.go index 0992f56..b511973 100644 --- a/server/cmd_list.go +++ b/server/cmd_list.go @@ -198,6 +198,21 @@ func lttlCommand(c *client) error { return nil } +func lpersistCommand(c *client) error { + args := c.args + if len(args) != 1 { + return ErrCmdParams + } + + if n, err := c.db.LPersist(args[0]); err != nil { + return err + } else { + c.writeInteger(n) + } + + return nil +} + func init() { register("lindex", lindexCommand) register("llen", llenCommand) @@ -213,4 +228,5 @@ func init() { register("lexpire", lexpireCommand) register("lexpireat", lexpireAtCommand) register("lttl", lttlCommand) + register("lpersist", lpersistCommand) } diff --git a/server/cmd_ttl_test.go b/server/cmd_ttl_test.go index c312ba7..664ca87 100644 --- a/server/cmd_ttl_test.go +++ b/server/cmd_ttl_test.go @@ -60,4 +60,22 @@ func TestKVExpire(t *testing.T) { t.Fatal(false) } + if n, err := ledis.Int(c.Do("persist", k)); err != nil { + t.Fatal(err) + } else if n != 1 { + t.Fatal(n) + } + + if n, err := ledis.Int(c.Do("expire", k, 10)); err != nil { + t.Fatal(err) + } else if n != 1 { + t.Fatal(n) + } + + if n, err := ledis.Int(c.Do("persist", k)); 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 4411113..2c6fd7d 100644 --- a/server/cmd_zset.go +++ b/server/cmd_zset.go @@ -464,6 +464,21 @@ func zttlCommand(c *client) error { return nil } +func zpersistCommand(c *client) error { + args := c.args + if len(args) != 1 { + return ErrCmdParams + } + + if n, err := c.db.ZPersist(args[0]); err != nil { + return err + } else { + c.writeInteger(n) + } + + return nil +} + func init() { register("zadd", zaddCommand) register("zcard", zcardCommand) @@ -486,4 +501,5 @@ func init() { register("zexpire", zexpireCommand) register("zexpireat", zexpireAtCommand) register("zttl", zttlCommand) + register("zpersist", zpersistCommand) }