Redis基础教程第4节 Hash
Hasehes
Redis hash是一个string类型的field和value映射表。hash特别适合于存储对象。相对存成string,现在存为一个hash类型中可以占用更少的内存。且可以更方便的存储整个对象。
hset
redis127.0.0.1:6379>hsetuser:001namemichael(integer)1redis127.0.0.1:6379>hgetuser:001name"michael"
hsetnx
redis127.0.0.1:6379>hsetnxuser:003namejason(integer)1redis127.0.0.1:6379>hsetnxuser:003nametom(integer)0--setfailedredis127.0.0.1:6379>hgetuser:003name"jason"--valueisnotchanged.
hmset/hmget
redis127.0.0.1:6379>hmsetuser:004namemichaelage29sex1OKredis127.0.0.1:6379>hgetuser:004name"michael"redis127.0.0.1:6379>hgetuser:004age"29"redis127.0.0.1:6379>hgetuser:004sex"1"redis127.0.0.1:6379>hmgetuser:004nameagesex1)"michael"2)"29"3)"1"
hincrby
redis127.0.0.1:6379>hincrbyuser:004age5(integer)34redis127.0.0.1:6379>hgetuser:004age"34"
hexists
redis127.0.0.1:6379>hexistsuser:004age(integer)1redis127.0.0.1:6379>hexistsuser:004address(integer)0
hlen
redis127.0.0.1:6379>hlenuser:004(integer)3
hdel
redis127.0.0.1:6379>hdeluser:004age(integer)1redis127.0.0.1:6379>hexistsuser:004address(integer)0redis127.0.0.1:6379>hgetuser:004age(nil)
hkeyshvalshgetall
redis127.0.0.1:6379>hkeysuser:0041)"name"2)"sex"redis127.0.0.1:6379>hvalsuser:0041)"michael"2)"1"redis127.0.0.1:6379>hgetalluser:0041)"name"2)"michael"3)"sex"4)"1"
声明:本站所有文章资源内容,如无特殊说明或标注,均为采集网络资源。如若本站内容侵犯了原著者的合法权益,可联系本站删除。