标签:
# 测试数据redis> HGETALL abbr1) "a"2) "apple"3) "b"4) "banana"5) "c"6) "cat"7) "d"8) "dog"# 删除单个域redis> HDEL abbr a(integer) 1# 删除不存在的域redis> HDEL abbr not-exists-field(integer) 0# 删除多个域redis> HDEL abbr b c(integer) 2redis> HGETALL abbr1) "d"2) "dog"
redis> HEXISTS phone myphone(integer) 0redis> HSET phone myphone nokia-1110(integer) 1redis> HEXISTS phone myphone(integer) 1
# 域存在redis> HSET site redis redis.com(integer) 1redis> HGET site redis"redis.com"# 域不存在redis> HGET site mysql(nil)
redis> HSET people jack "Jack Sparrow"(integer) 1redis> HSET people gump "Forrest Gump"(integer) 1redis> HGETALL people1) "jack" # 域2) "Jack Sparrow" # 值3) "gump"4) "Forrest Gump"
# increment 为正数redis> HEXISTS counter page_view # 对空域进行设置(integer) 0redis> HINCRBY counter page_view 200(integer) 200redis> HGET counter page_view"200"# increment 为负数redis> HGET counter page_view"200"redis> HINCRBY counter page_view -50(integer) 150redis> HGET counter page_view"150"# 尝试对字符串值的域执行HINCRBY命令redis> HSET myhash string hello,world # 设定一个字符串值(integer) 1redis> HGET myhash string"hello,world"redis> HINCRBY myhash string 1 # 命令执行失败,错误。(error) ERR hash value is not an integerredis> HGET myhash string # 原值不变"hello,world"
# 值和增量都是普通小数redis> HSET mykey field 10.50(integer) 1redis> HINCRBYFLOAT mykey field 0.1"10.6"# 值和增量都是指数符号redis> HSET mykey field 5.0e3(integer) 0redis> HINCRBYFLOAT mykey field 2.0e2"5200"# 对不存在的键执行 HINCRBYFLOATredis> EXISTS price(integer) 0redis> HINCRBYFLOAT price milk 3.5"3.5"redis> HGETALL price1) "milk"2) "3.5"# 对不存在的域进行 HINCRBYFLOATredis> HGETALL price1) "milk"2) "3.5"redis> HINCRBYFLOAT price coffee 4.5 # 新增 coffee 域"4.5"redis> HGETALL price1) "milk"2) "3.5"3) "coffee"4) "4.5"
# 哈希表非空redis> HMSET website google www.google.com yahoo www.yahoo.comOKredis> HKEYS website1) "google"2) "yahoo"# 空哈希表/key不存在redis> EXISTS fake_key(integer) 0redis> HKEYS fake_key(empty list or set)
redis> HSET db redis redis.com(integer) 1redis> HSET db mysql mysql.com(integer) 1redis> HLEN db(integer) 2redis> HSET db mongodb mongodb.org(integer) 1redis> HLEN db(integer) 3
redis> HMSET pet dog "doudou" cat "nounou" # 一次设置多个域OKredis> HMGET pet dog cat fake_pet # 返回值的顺序和传入参数的顺序一样1) "doudou"2) "nounou"3) (nil) # 不存在的域返回nil值
redis> HMSET website google www.google.com yahoo www.yahoo.comOKredis> HGET website google"www.google.com"redis> HGET website yahoo"www.yahoo.com"
redis> HSET website google "www.g.cn" # 设置一个新域(integer) 1redis> HSET website google "www.google.com" # 覆盖一个旧域(integer) 0
redis> HSETNX nosql key-value-store redis(integer) 1redis> HSETNX nosql key-value-store redis # 操作无效,域 key-value-store 已存在(integer) 0
# 非空哈希表redis> HMSET website google www.google.com yahoo www.yahoo.comOKredis> HVALS website1) "www.google.com"2) "www.yahoo.com"# 空哈希表/不存在的keyredis> EXISTS not_exists(integer) 0redis> HVALS not_exists(empty list or set)
标签:
原文地址:http://blog.csdn.net/mergades/article/details/46467551