[Redis Chapter4] Hash

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了[Redis Chapter4] Hash相关的知识,希望对你有一定的参考价值。

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的主要内容,如果未能解决你的问题,请参考以下文章

STA基础chapter4

面向对象chapter4

《图解密码技术》Chapter4:分组密码的主要模式

Python编程:从入门到实践chapter4 操作列表

Graph Representation Learning学习笔记-chapter4

chapter4 module and port