forked from mirror/ledisdb
add hmclear, lmclear and zmclear for multi keys
This commit is contained in:
parent
c2cfc60cf8
commit
46d2ecda91
|
@ -557,13 +557,13 @@ ledis> hvals myhash
|
|||
2) "world"
|
||||
```
|
||||
|
||||
### hclear key
|
||||
### hclear key
|
||||
|
||||
Deletes the hash key
|
||||
Deletes the specified hash keys
|
||||
|
||||
**Return value**
|
||||
|
||||
int64: the number of fields in the hash stored at key.
|
||||
int64: the number of fields in the hash stored at key
|
||||
|
||||
**Examples**
|
||||
|
||||
|
@ -574,6 +574,23 @@ ledis> hclear myhash
|
|||
(integer) 2
|
||||
```
|
||||
|
||||
### hmclear key [key...]
|
||||
|
||||
Deletes the specified hash keys
|
||||
|
||||
**Return value**
|
||||
|
||||
int64: the number of input keys
|
||||
|
||||
**Examples**
|
||||
|
||||
```
|
||||
ledis> hmset myhash field1 "hello" field2 "world"
|
||||
OK
|
||||
ledis> hclear myhash
|
||||
(integer) 1
|
||||
```
|
||||
|
||||
### hexpire key seconds
|
||||
|
||||
Sets a hash key's time to live in seconds, like expire similarly.
|
||||
|
|
|
@ -434,6 +434,24 @@ func (db *DB) HClear(key []byte) (int64, error) {
|
|||
return num, err
|
||||
}
|
||||
|
||||
func (db *DB) HMclear(keys ...[]byte) (int64, error) {
|
||||
t := db.hashTx
|
||||
t.Lock()
|
||||
defer t.Unlock()
|
||||
|
||||
for _, key := range keys {
|
||||
if err := checkKeySize(key); err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
db.hDelete(t, key)
|
||||
db.rmExpire(t, hExpType, key)
|
||||
}
|
||||
|
||||
err := t.Commit()
|
||||
return int64(len(keys)), err
|
||||
}
|
||||
|
||||
func (db *DB) hFlush() (drop int64, err error) {
|
||||
t := db.kvTx
|
||||
t.Lock()
|
||||
|
|
|
@ -395,6 +395,25 @@ func (db *DB) LClear(key []byte) (int64, error) {
|
|||
return num, err
|
||||
}
|
||||
|
||||
func (db *DB) LMclear(keys ...[]byte) (int64, error) {
|
||||
t := db.listTx
|
||||
t.Lock()
|
||||
defer t.Unlock()
|
||||
|
||||
for _, key := range keys {
|
||||
if err := checkKeySize(key); err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
db.lDelete(t, key)
|
||||
db.rmExpire(t, lExpType, key)
|
||||
|
||||
}
|
||||
|
||||
err := t.Commit()
|
||||
return int64(len(keys)), err
|
||||
}
|
||||
|
||||
func (db *DB) lFlush() (drop int64, err error) {
|
||||
t := db.listTx
|
||||
t.Lock()
|
||||
|
|
|
@ -631,6 +631,22 @@ func (db *DB) ZClear(key []byte) (int64, error) {
|
|||
return rmCnt, err
|
||||
}
|
||||
|
||||
func (db *DB) ZMclear(keys ...[]byte) (int64, error) {
|
||||
t := db.zsetTx
|
||||
t.Lock()
|
||||
defer t.Unlock()
|
||||
|
||||
for _, key := range keys {
|
||||
if _, err := db.zRemRange(t, key, MinScore, MaxScore, 0, -1); err != nil {
|
||||
return 0, err
|
||||
}
|
||||
}
|
||||
|
||||
err := t.Commit()
|
||||
|
||||
return int64(len(keys)), err
|
||||
}
|
||||
|
||||
func (db *DB) ZRange(key []byte, start int, stop int) ([]ScorePair, error) {
|
||||
return db.ZRangeGeneric(key, start, stop, false)
|
||||
}
|
||||
|
|
|
@ -207,6 +207,21 @@ func hclearCommand(c *client) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
func hmclearCommand(c *client) error {
|
||||
args := c.args
|
||||
if len(args) < 1 {
|
||||
return ErrCmdParams
|
||||
}
|
||||
|
||||
if n, err := c.db.HMclear(args...); err != nil {
|
||||
return err
|
||||
} else {
|
||||
c.writeInteger(n)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func hexpireCommand(c *client) error {
|
||||
args := c.args
|
||||
if len(args) == 0 {
|
||||
|
@ -293,6 +308,7 @@ func init() {
|
|||
//ledisdb special command
|
||||
|
||||
register("hclear", hclearCommand)
|
||||
register("hmclear", hmclearCommand)
|
||||
register("hexpire", hexpireCommand)
|
||||
register("hexpireat", hexpireAtCommand)
|
||||
register("httl", httlCommand)
|
||||
|
|
|
@ -143,6 +143,21 @@ func lclearCommand(c *client) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
func lmclearCommand(c *client) error {
|
||||
args := c.args
|
||||
if len(args) < 1 {
|
||||
return ErrCmdParams
|
||||
}
|
||||
|
||||
if n, err := c.db.LMclear(args...); err != nil {
|
||||
return err
|
||||
} else {
|
||||
c.writeInteger(n)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func lexpireCommand(c *client) error {
|
||||
args := c.args
|
||||
if len(args) == 0 {
|
||||
|
@ -225,6 +240,7 @@ func init() {
|
|||
//ledisdb special command
|
||||
|
||||
register("lclear", lclearCommand)
|
||||
register("lmclear", lmclearCommand)
|
||||
register("lexpire", lexpireCommand)
|
||||
register("lexpireat", lexpireAtCommand)
|
||||
register("lttl", lttlCommand)
|
||||
|
|
|
@ -409,6 +409,21 @@ func zclearCommand(c *client) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
func zmclearCommand(c *client) error {
|
||||
args := c.args
|
||||
if len(args) < 1 {
|
||||
return ErrCmdParams
|
||||
}
|
||||
|
||||
if n, err := c.db.ZMclear(args...); err != nil {
|
||||
return err
|
||||
} else {
|
||||
c.writeInteger(n)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func zexpireCommand(c *client) error {
|
||||
args := c.args
|
||||
if len(args) == 0 {
|
||||
|
@ -498,6 +513,7 @@ func init() {
|
|||
//ledisdb special command
|
||||
|
||||
register("zclear", zclearCommand)
|
||||
register("zmclear", zmclearCommand)
|
||||
register("zexpire", zexpireCommand)
|
||||
register("zexpireat", zexpireAtCommand)
|
||||
register("zttl", zttlCommand)
|
||||
|
|
Loading…
Reference in New Issue