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的個數(shù):
HLEN user:1000 => "(integer) 2"
HSTRLEN命令獲取某個field值的長度:
HSTRLEN user:1000 name => "(integer) 8"
HINCRBY和HINCRBYFLOAT命令可以增加hash中某個field對應的值。