下列这些数据类型都可作为值类型:

  • 二进制安全的字符串

  • Lists: 按插入顺序排序的字符串元素的集合。他们基本上就是 链表(linked lists)
  • Sets: 不重复且无序的字符串元素的集合。
  • Sorted sets,类似Sets,但是每个字符串元素都关联到一个叫 score 浮动数值(floating number value)。里面的元素总是通过score进行着排序,所以不同的是,它是可以检索的一系列元素。(例如你可能会问:给我前面10个或者后面10个元素)。
  • Hashes,由field和关联的value组成的map。field和value都是字符串的。这和Ruby、Python的hashes很像。
  • Bit arrays (或者说 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.

Lists

说明:Redis lists基于Linked Lists实现,写性能高效,但是不适合随机读,适用场景:

  1. 基于LPUSHRPUSH、rpop、lpop命令用于获取或删除第一个节点或最后一个节点,可以基于该命令模拟实现队列、栈功能;
  2. LRANGE获取部分元素,可实现分页功能;
  3. BRPOPBLPOP,阻塞命令,可以实现生产者消费者模型。

results matching ""

    No results matching ""