redis 数据类型

今天有兴趣研究redis内部的数据类型,其实从官网的介绍中,redis的数据类型总共有8种,Strings、Lists、Hashes、Sets、Sorted sets、Bitmaps、HyperLogLogs、Streams摘抄官网文档如下:

  • Binary-safe strings.
  • Lists: collections of string elements sorted according to the order of insertion. They are basically linked lists.
  • Sets: collections of unique, unsorted string elements.
  • Sorted sets, similar to Sets but where every string element is associated to a floating number value, called score. The elements are always taken sorted by their score, so unlike Sets it is possible to retrieve a range of elements (for example you may ask: give me the top 10, or the bottom 10).
  • Hashes, which are maps composed of fields associated with values. Both the field and the value are strings. This is very similar to Ruby or Python hashes.
  • Bit arrays (or simply bitmaps): it is possible, using special commands, to handle String values like an array of bits: you can set and clear individual bits, count all the bits set to 1, find the first set or unset bit, and so forth.
  • HyperLogLogs: this is a probabilistic data structure which is used in order to estimate the cardinality of a set. Don't be scared, it is simpler than it seems... See later in the HyperLogLog section of this tutorial.
  • Streams: append-only collections of map-like entries that provide an abstract log data type. They are covered in depth in the Introduction to Redis Streams.

 

1.String

Redis String类型是可以与Redis键关联的最简单的值类型。 它是Memcached中唯一的数据类型,因此新手在Redis中使用它也很自然。由于Redis键是字符串,当我们使用字符串类型作为值时,我们将字符串映射到另一个字符串。 字符串数据类型对于许多用例很有用,例如缓存HTML片段或页面。

String类型就是在redis中以value为String类型去存储数据对象。

在java中它的操作方法有如下几种

5de17064e44fd717ab7b94ccc0d96fee911.jpg

 

2.List

所谓list数据结构,就是value是list类型,我们可以通过lpush、rpush去存数据,lpop、rpop去取出数据,可以通过lset去修改list某个index下的数据。

example:

e20e8d8cc010d299049b900bf8a9910e521.jpg

list 中index = 2的数据成功被更新为update

c234098c6ac1b6daf30b869e7d7ee6ab815.jpg

具体操作如下

c9d64cf66fcb8cb69943e52f13a06b3e74a.jpg

3.set

redis中set数据结构是指,value为set数据结构的数据,其中set是不允许重复的元素出现

ca53f6b86495569030dba2537543ee2cf54.jpg

有交并差的方法,这里就不做展示了

4.Map

map在redis中就是value为map数据结构的key-value的存在。

1db7b3cff98b75ea2a29a68511548ed5118.jpg

5. Sorted set

Sorted set是一个有序的set集合,redis会为这种数据结构的数据集合进行排序。

6494bb1e12d3998a84f19aac8d8e10d13e4.jpg

其他方法这里就不介绍了。

 

到最后,以上这些就是对redis数据结构的介绍,觉得好的可以点个赞

转载于:https://my.oschina.net/u/4095089/blog/3095760

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值