lxy777 发表于 2018-11-6 10:36:10

redis的小结

  redis使用场景如下:
  1.在主页中显示最新的项目列表。
  2.删除和过滤
  3.排行榜及相关问题。
  4.按照用户投票和时间排序。
  5.过期项目处理。
  6.计数。
  7.特定时间内的特定项目。
  8.实时分析正在发生的情况,用于数据统计与防止垃圾邮件等。
  9.Pub/Sub。
  10.队列。
  11.缓存。
  12.关注者列表。
  13.共同关注。
  ...............
  1、redis包含如下结构(引自官方):

[*]  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.
  2、String类型小结
  a)、string类型的value最大为512M。可以存储任何类型的数据。
  b)、mset,msetnx区别,使用msetnx时,只要有一个key存在,则该语句就不执行。
  c)、用于统计用户每月登录次数时,可使用setbit,getbit,bitcount,占用空间小且方便。
  3、list类型小结
  a)、string类型的232 - 1 ,当列表数据达到几百万时,访问数据依然很快(访问列表中间数据时较慢),时间复杂度O(N)。
  b)、使用时间轴时,可以使用lpush将数据放在最上面,通过lrange来获取数据
  c)、通过ltrim删除不访问的数据来达到top N的结果。
  d)、BLPOP、BRPOP、BRPOPLPUSH获取数据时,会阻塞当前进程,直到获取数据或到了指定的时间(单位s)

页: [1]
查看完整版本: redis的小结