码迷,mamicode.com
首页 > 其他好文 > 详细

[Redis Chapter4] Hash

时间:2016-05-26 11:39:23      阅读:122      评论:0      收藏:0      [点我收藏+]

标签:hash   redis   

Hasehes 

Redis hash是一个string类型的field和value映射表。hash特别适合于存储对象。相对存成string,现在存为一个hash类型中可以占用更少的内存。且可以更方便的存储整个对象。


hset

redis 127.0.0.1:6379> hset user:001 name michael

(integer) 1

redis 127.0.0.1:6379> hget user:001 name

"michael"


hsetnx

redis 127.0.0.1:6379> hsetnx user:003 name jason

(integer) 1

redis 127.0.0.1:6379> hsetnx user:003 name tom

(integer) 0 -- set failed

redis 127.0.0.1:6379> hget user:003 name

"jason"  -- value is not changed.


hmset/hmget


redis 127.0.0.1:6379> hmset user:004 name michael age 29 sex 1

OK

redis 127.0.0.1:6379> hget user:004 name

"michael"

redis 127.0.0.1:6379> hget user:004 age

"29"

redis 127.0.0.1:6379> hget user:004 sex

"1"

redis 127.0.0.1:6379> hmget user:004 name age sex

1) "michael"

2) "29"

3) "1"


hincrby 

redis 127.0.0.1:6379> hincrby user:004 age 5

(integer) 34

redis 127.0.0.1:6379> hget user:004 age

"34"


hexists 

redis 127.0.0.1:6379> hexists user:004 age

(integer) 1

redis 127.0.0.1:6379> hexists user:004 address

(integer) 0


hlen 

redis 127.0.0.1:6379> hlen user:004

(integer) 3


hdel 

redis 127.0.0.1:6379> hdel user:004 age

(integer) 1

redis 127.0.0.1:6379> hexists user:004 address

(integer) 0

redis 127.0.0.1:6379> hget user:004 age

(nil)


hkeys hvals hgetall 

redis 127.0.0.1:6379> hkeys user:004

1) "name"

2) "sex"

redis 127.0.0.1:6379> hvals user:004

1) "michael"

2) "1"

redis 127.0.0.1:6379> hgetall user:004

1) "name"

2) "michael"

3) "sex"

4) "1"




本文出自 “软件设计与开发” 博客,请务必保留此出处http://yuanzhitang.blog.51cto.com/2769219/1783356

[Redis Chapter4] Hash

标签:hash   redis   

原文地址:http://yuanzhitang.blog.51cto.com/2769219/1783356

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!