Hash


hash类型跟string有所不同。它适合于存储对象。一个hash集合可以存储多个string类型,即可以存储多个键值对。


hset


hset user id 1
hset user name Howard
hset user age 20
hset user sex man






redis hmset用法 redis hset hget_数据库


redis hmset用法 redis hset hget_redis_02


hget


获取某hash里的键值对


hget hashname key


如:


hget user name




redis hmset用法 redis hset hget_centos_03


hmset


类似mset


同时建立多个键值对存储。


hmset user2 id 2 name tom age 21 sex man



hmget


类似mget 同时获取对个值


hmget user2 id name






redis hmset用法 redis hset hget_centos_04


当然也有hsetnx和hsetex,与setnx和setex类似。


hincrby和hdecrby,与incrby和decrby类似。不举更多例子了。

redis hmset用法 redis hset hget_hash_05





hexists


是否存在key 存在返回1 不存在返回0


例如:


hexists user2 age


redis hmset用法 redis hset hget_redis_06


hlen


返回hash集合里所有的键数值


hlen user


redis hmset用法 redis hset hget_hash_07


hkeys


返回hash里所有字段


hkeys user


redis hmset用法 redis hset hget_数据库_08


hvals


返回hash里所有value


hvals user


redis hmset用法 redis hset hget_数据库_09


hgetall


返回hash里所有的key和value


hgetall user


redis hmset用法 redis hset hget_存储_10


hdel


删除指定的hash的某个键值对s


hdel user sex


redis hmset用法 redis hset hget_hash_11