redis的小結

來源:互聯網
上載者:User

標籤: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)

本文出自 “peter的未來” 部落格,請務必保留此出處http://peterxu.blog.51cto.com/1391852/1661322

redis的小結

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.