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數據結構的介紹,以爲好的能夠點個贊

相關文章
相關標籤/搜索