redis 数据类型

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

  • 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.Stringredis

Redis String类型是能够与Redis键关联的最简单的值类型。 它是Memcached中惟一的数据类型,所以新手在Redis中使用它也很天然。因为Redis键是字符串,当咱们使用字符串类型做为值时,咱们将字符串映射到另外一个字符串。 字符串数据类型对于许多用例颇有用,例如缓存HTML片断或页面。缓存

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

在java中它的操做方法有以下几种app

 

2.Listide

所谓list数据结构,就是value是list类型,咱们能够经过lpush、rpush去存数据,lpop、rpop去取出数据,能够经过lset去修改list某个index下的数据。this

example:spa

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

具体操做以下blog

3.set

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

有交并差的方法,这里就不作展现了

4.Map

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

5. Sorted set

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

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

 

到最后,以上这些就是对redis数据结构的介绍,以为好的能够点个赞

相关文章
相关标签/搜索