add persist command

This commit is contained in:
siddontang 2014-06-24 12:44:44 +08:00
parent 8c3ac7ebfb
commit 31e70ccd02
5 changed files with 82 additions and 0 deletions

View File

@ -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)
}

View File

@ -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)
}

View File

@ -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)
}

View File

@ -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)
}
}

View File

@ -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)
}