Redis命令:Hashes

2016-06-13  本文已影响42人  yingzong

HSET命令可以设置hash中一个field的值:

HSET user:1000 name yingzong => "(integer) 1"

HGET命令可以获取hash中一个field的值:

HGET user:1000 name => "yingzong"

HMSETHMGET命令可以批量设置/获取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"

HINCRBYHINCRBYFLOAT命令可以增加hash中某个field对应的值。

上一篇 下一篇

猜你喜欢

热点阅读