注意:此文档已经过期,请移步到 http://huangz.iteye.com/blog/1123512 查看最新翻译。
redis> HSET hash_name jack "Jack Sparrow" (integer) 1 redis> HGET hash_name jack "Jack Sparrow" redis> HDEL hash_name jack (integer) 1 redis> HGET hash_name jack (nil)
redis> HSET hash_name jack "Jack Sparrow" (integer) 1 redis> HSET hash_name gump "Forrest Gump" (integer) 1 redis> HGETALL hash_name 1) "jack" # 域 2) "Jack Sparrow" # 值 3) "gump" 4) "Forrest Gump"
redis> HSET hash_name jack "Jack Sparrow" (integer) 1 redis> HSET hash_name gump "Forrest Gump" (integer) 1 redis> HLEN hash_name (integer) 2
redis> HSET website google "www.g.cn" (integer) 1 redis> HSET website google "www.google.com" (integer) 0
redis> HEXISTS phone myphone (integer) 0 redis> HSET phone myphone nokia-1110 (integer) 1 redis> HEXISTS phone myphone (integer) 1
redis> HEXISTS hash_count page_views (integer) 0 redis> HINCRBY hash_count page_views 200 (integer) 200 redis> HINCRBY hash_count page_views 10 (integer) 210
redis> HMSET pet dog "doudou" cat "nounou" # 一次保存多个值 OK redis> HMGET pet dog cat fake_pet # 返回值的顺序和传入参数的顺序一样。 1) "doudou" 2) "nounou" 3) (nil) # 不存在的域返回nil值
redis> HSETNX nosql key-value-store redis (integer) 1 redis> HSETNX nosql key-value-store redis # 操作无效,域key-value-store已存在 (integer) 0
redis> HSET huangz blog www.SideEffect.me (integer) 1 redis> HGET huangz blog "www.SideEffect.me"
redis> HMSET website google www.google.com yahoo www.yahoo.com OK redis> HKEYS website 1) "google" 2) "yahoo" redis> EXISTS fake_key (integer) 0 redis> HKEYS fake_key # 对不存在的key进行HKEYS操作,返回一个空表 (empty list or set)
redis> HMSET website google www.google.com yahoo www.yahoo.com OK redis> HGET website google "www.google.com" redis> HGET website yahoo "www.yahoo.com"
redis> HMSET website google www.google.com yahoo www.yahoo.com OK redis> HVALS website 1) "www.google.com" 2) "www.yahoo.com"