mirror of
https://github.com/HDT3213/godis.git
synced 2025-10-16 22:00:39 +08:00
Feat: Add HStrlen Command.
This commit is contained in:
@@ -187,6 +187,28 @@ func execHLen(db *DB, args [][]byte) redis.Reply {
|
||||
return protocol.MakeIntReply(int64(dict.Len()))
|
||||
}
|
||||
|
||||
// execHStrlen Returns the string length of the value associated with field in the hash stored at key.
|
||||
// If the key or the field do not exist, 0 is returned.
|
||||
func execHStrlen(db *DB, args [][]byte) redis.Reply {
|
||||
key := string(args[0])
|
||||
field := string(args[1])
|
||||
|
||||
dict, errReply := db.getAsDict(key)
|
||||
if errReply != nil {
|
||||
return errReply
|
||||
}
|
||||
if dict == nil {
|
||||
return protocol.MakeIntReply(0)
|
||||
}
|
||||
|
||||
raw, exists := dict.Get(field)
|
||||
if exists {
|
||||
value, _ := raw.([]byte)
|
||||
return protocol.MakeIntReply(int64(len(value)))
|
||||
}
|
||||
return protocol.MakeIntReply(0)
|
||||
}
|
||||
|
||||
// execHMSet sets multi fields in hash table
|
||||
func execHMSet(db *DB, args [][]byte) redis.Reply {
|
||||
// parse args
|
||||
@@ -482,6 +504,7 @@ func init() {
|
||||
RegisterCommand("HExists", execHExists, readFirstKey, nil, 3)
|
||||
RegisterCommand("HDel", execHDel, writeFirstKey, undoHDel, -3)
|
||||
RegisterCommand("HLen", execHLen, readFirstKey, nil, 2)
|
||||
RegisterCommand("HStrlen", execHStrlen, readFirstKey, nil, 3)
|
||||
RegisterCommand("HMSet", execHMSet, writeFirstKey, undoHMSet, -4)
|
||||
RegisterCommand("HMGet", execHMGet, readFirstKey, nil, -3)
|
||||
RegisterCommand("HGet", execHGet, readFirstKey, nil, -3)
|
||||
|
Reference in New Issue
Block a user