HSET
命令可以设置hash中一个field的值:
HSET user:1000 name yingzong => "(integer) 1"
HGET
命令可以获取hash中一个field的值:
HGET user:1000 name => "yingzong"
HMSET
和HMGET
命令可以批量设置/获取field:
HMSET user:1000 age 18 location "hangzhou" => "OK"
HMGET user:1000 name age
=> 1) "yingzong"
=> 2) "18"
HGETALL
获取所有的filed名和值。
HGETALL user:1000
=> 1) "name"
=> 2) "yingzong"
=> 3) "age"
=> 4) "18"
=> 5) "location"
=> 6) "hangzhou"
HKEYS
获取所有的field名。
HKEYS user:1000
=> 1) "name"
=> 2) "age"
=> 3) "location"
HVALS
获取所有的field值。
HVALS user:1000
=> 1) "yingzong"
=> 2) "18"
=> 3) "hangzhou"
HSETNX
名字只有field不存在时才设置:
HSETNX user:1000 name "test" => "(integer) 0"
HDEL
命令用于删除field:
HDEL user:1000 location => "(integer) 1"
HEXISTS
命令用于判断field是否存在:
HEXISTS user:1000 location => "(integer) 0"
HLEN
命令可以获取hash中field的个数:
HLEN user:1000 => "(integer) 2"
HSTRLEN
命令获取某个field值的长度:
HSTRLEN user:1000 name => "(integer) 8"
HINCRBY
和HINCRBYFLOAT
命令可以增加hash中某个field对应的值。