forked from mirror/ledisdb
add persist command
This commit is contained in:
parent
8c3ac7ebfb
commit
31e70ccd02
|
@ -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)
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue