在线观看不卡亚洲电影_亚洲妓女99综合网_91青青青亚洲娱乐在线观看_日韩无码高清综合久久

鍍金池/ 教程/ 大數(shù)據(jù)/ 4.6 典型使用場景參考
6.2 并發(fā)延遲檢查
2.2.2 獲取key對應的string值
11.1.5 其他問題
4.7 客戶端推薦
3.3 查看和修改配置
2.3.7 設置list中指定下標的元素值
9.1 Shell提權問題
2.3.6 刪除元素
8.3.1 系統(tǒng)內(nèi)存查看
11.1.2 環(huán)境搭建
2.6.3 遞增某一個域的值
2.7.2 返回給定 HyperLogLog 的基數(shù)估算值
2.3.8 阻塞隊列
2.5.2 刪除元素
2.4.6 查看集合大小
8.3.4 dump.rdb文件成生內(nèi)存報告(rdb-tool)
8.3 內(nèi)存檢查
2.1.7 Key的超時設置處理
2.5.8 返回集合中元素個數(shù)
2.7.1 將元素添加至 HyperLogLog
2.5.4 獲取排名
6.1.2 探測服務延遲
10.1 概念
7.3 模擬hang
2.6.6 獲取域的數(shù)量
11.1.1 高可用原理
3.5 選擇數(shù)據(jù)庫
4.3 數(shù)據(jù)異常處理
2.4.10 集合差集
2.2.6 改寫字符串
11.1.3 維護操作
3.13.3 備份
2.2.5 截取字符串
4.6 典型使用場景參考
2.4.4 隨機返回一個元素
2.4.11 獲取所有元素
2.4.3 刪除并返回元素
2.4.2 移除元素
8.3.9 Rss增加,內(nèi)存碎片增加
2.4.8 集合交集
2.1.3 刪除給定key
2.5.3 增加score
11.1.4 高可用和異常測試
底層實現(xiàn)是hash table,一般操作復雜度是O(1),要同時操作多個field時就是O(N),N是field的數(shù)量。應用場景
5.2 網(wǎng)卡RPS設置
2.6.7 獲取所有的域名
5.6 具體設置參數(shù)
生產(chǎn)環(huán)境慎用。
6. 常見運維操作
8.3.8 查看key內(nèi)部結構和編碼等信息
4.4 內(nèi)存考慮
4.1 Key設計
2.5.5 獲取排行榜
7.1 模擬oom
2.1.2 測試指定key是否存在
10.3 分片主要場景和對應思路
6.1.1 探測服務是否可用
3.13.1 RDB相關操作
2.3.5 截取list
3.13.4 恢復
3.10 驗證密碼
2.2.4 追加字符串
8.3.6 內(nèi)存抽樣分析
5. 上線部署規(guī)劃
Sorted Set的實現(xiàn)是hash table(element->score, 用于實現(xiàn)ZScore及判斷element
4.5 延遲考慮
2.6.1 設置hash值
8.3.5 query在線分析
6.2.4 檢查連接數(shù)
2.4.9 集合并集
7. 數(shù)據(jù)遷移
4. 開發(fā)設計規(guī)范
2.5.9 返回給定元素對應的score
9. Redis安全問題
2.2.7 返回子字符串
3.4 批量執(zhí)行操作
Server
3.1 排序
8.3.2 系統(tǒng)swap內(nèi)存查看
2.6.4 判斷某一個域是否存在
3.6 清空數(shù)據(jù)庫
2.6.8 獲取所有域的值
3.11 性能測試命令
  • 1.
6.2.1 檢查CPU情況
7.5 模擬RDB load情形
7.4 快速產(chǎn)生測試數(shù)據(jù)
7.2 模擬宕機
2.7.3 合并多個 HyperLogLog
  • 1.
9. 測試方法
2.7 HyperLogLog操作
3.7 重命名命令
6.1.7 查看日志
6.2.5 檢查持久化
4.2 超時設置
8.1 一般處理流程
2.1.4 返回給定key的value類型
5.3 服務器部署位置
2.5.6 返回給定分數(shù)區(qū)間的元素
6.2.6 檢查命令執(zhí)行情況
7.6 模擬AOF加載情形
6.13 持久化與備份恢復
5.1 內(nèi)存、CPU規(guī)劃
5.5 多實例配置
2.2.1 設置key對應的值為string類型的value
6.1.5 獲取慢查詢
incr key
3.4 發(fā)布訂閱
6.2.2 檢查網(wǎng)絡情況
2.6.5 刪除域
6.2.3 檢查系統(tǒng)情況
8. 數(shù)據(jù)遷移
2.5.7 返回集合中score在給定區(qū)間的數(shù)量
2.1. key操作
3.8 執(zhí)行l(wèi)ua腳本
1. 簡述
11.1 主從復制-sentinel架構
2.3.2 查看列表長度
8.3.3 info查看內(nèi)存
2.6.2 獲取hash值
11. 高可用和集群架構與實踐
3.13.2 AOF相關操作
2. 數(shù)據(jù)操作
3.3 流水線
3.1 啟動
2.3.3 查看元素
2.4.5 集合間移動元素
8.3.7 統(tǒng)計生產(chǎn)上比較大的key
10.4 適用場景對比列表
3.9 設置密碼
3.2 事務
2.1.5 返回從當前數(shù)據(jù)庫中隨機選擇的一個key
5.7 其他好用的配置技巧
3. 專題功能
2.3.4 查看一段列表
2.4.7 判斷member是否在set中
2.4.1 添加元素
2.1.6 原子的重命名一個key
2.1.1 列出key
2.6.9 獲取所有域名和值
2.5.10 評分的聚合
3.12 Redis-cli命令行其他操作
最大字符串為512M,但是大字符串非常不建議。
4.1 將key從當前數(shù)據(jù)庫移動到指定數(shù)據(jù)庫
6.1.6 查看客戶端
10. 簡述
2.2.10 位操作
2.2.9 取指定key的value值的長度
  • 1.
3.2 停止
5.4 持久化設置
10.2 高可用主要場景和對應思路
2.5.1 添加元素
2.3.1 添加元素

4.6 典型使用場景參考

下面是Redis適用的一些場景:

1. 取最新 N 個數(shù)據(jù)的操作

比如典型的取你網(wǎng)站的最新文章,通過下面方式,我們可以將最新的 5000條評論的ID放在Redis的List集合中,并將超出集合部分從數(shù)據(jù)庫獲取。

使用LPUSH latest.comments命令,向 list集合中插入數(shù)據(jù) 插入完成后再用 LTRIM latest.comments 0 5000 命令使其永遠只保存最近5000個 ID 然后我們在客戶端獲取某一頁評論時可以用下面的邏輯

FUNCTION get_latest_comments(start,num_items):
 id_list = redis.lrange("latest.comments",start,start+num_items-1) 
 IF id_list.length < num_items 
 id_list = SQL_DB("SELECT ... ORDER BY time LIMIT ...") 
 END 
 RETURN id_list 
END 

如果你還有不同的篩選維度,比如某個分類的最新 N 條,那么你可以再建一個按此分類的List,只存ID的話,Redis是非常高效的。

2. 排行榜應用,取 TOP N 操作

這個需求與上面需求的不同之處在于,前面操作以時間為權重,這個是以某個條件為權重,比如按頂?shù)拇螖?shù)排序,這時候就需要我們的 sorted set出馬了,將你要排序的值設置成 sorted set的score,將具體的數(shù)據(jù)設置成相應的 value,每次只需要執(zhí)行一條ZADD命令即可。

127.0.0.1:6379> zdd topapp 1 weixin
(error) ERR unknown command 'zdd'
127.0.0.1:6379> zadd topapp 1 weixin
(integer) 1
127.0.0.1:6379> zadd topapp 1 QQ
(integer) 1
127.0.0.1:6379> zadd topapp 2 meituan
(integer) 1
127.0.0.1:6379> zincrby topapp 1 meituan
"3"
127.0.0.1:6379> zincrby topapp 1 QQ
"2"
127.0.0.1:6379> zrank topapp QQ
(integer) 1
3) "meituan"
127.0.0.1:6379> zrank topapp weixin
(integer) 0
127.0.0.1:6379> zrange topapp 0 -1
1) "weixin"
2) "QQ"

3.需要精準設定過期時間的應用

比如你可以把上面說到的 sorted set 的 score 值設置成過期時間的時間戳,那么就可以簡單地通過過期時間排序,定時清除過期數(shù)據(jù)了,不僅是清除 Redis中的過期數(shù)據(jù),你完全可以把 Redis 里這個過期時間當成是對數(shù)據(jù)庫中數(shù)據(jù)的索引,用 Redis 來找出哪些數(shù)據(jù)需要過期刪除,然后再精準地從數(shù)據(jù)庫中刪除相應的記錄。

4.計數(shù)器應用

Redis的命令都是原子性的,你可以輕松地利用 INCR,DECR 命令來構建計數(shù)器系統(tǒng)。

5.Uniq 操作,獲取某段時間所有數(shù)據(jù)排重值

這個使用Redis的 set數(shù)據(jù)結構最合適了,只需要不斷地將數(shù)據(jù)往 set中扔就行了,set意為集合,所以會自動排重。

6.實時系統(tǒng),反垃圾系統(tǒng)

通過上面說到的 set功能,你可以知道一個終端用戶是否進行了某個操作,可以找到其操作的集合并進行分析統(tǒng)計對比等。

7.Pub/Sub 構建實時消息系統(tǒng)

Redis 的 Pub/Sub 系統(tǒng)可以構建實時的消息系統(tǒng),比如很多用 Pub/Sub 構建的實時聊天系統(tǒng)的例子。

8.構建隊列系統(tǒng)

使用list可以構建隊列系統(tǒng),使用 sorted set甚至可以構建有優(yōu)先級的隊列系統(tǒng)。

9.緩存

性能優(yōu)于Memcached,數(shù)據(jù)結構更多樣化。作為RDBMS的前端擋箭牌,redis可以對一些使用頻率極高的sql操作進行cache,比如,我們可以根據(jù)sql的hash進行SQL結果的緩存:

def get_results(sql):
    hash = md5.new(sql).digest()
    result = redis.get(hash)
    if result is None:
        result = db.execute(sql)
        redis.set(hash, result)
        # or use redis.setex to set a TTL for the key
    return result

10.使用setbit進行統(tǒng)計計數(shù)

下邊的例子是記錄UV

#!/usr/bin/python
import redis
from bitarray import bitarray
from datetime import date

r=redis.Redis(host='localhost', port=6379, db=0)
today=date.today().strftime('%Y-%m-%d')

def bitcount(n):
len(bin(n)-2)

def setup():
r.delete('user:'+today)
r.setbit('user:'+today,100,0)

def setuniquser(uid):
r.setbit('user:'+today,uid,1)

def countuniquser():
a = bitarray()
a.frombytes(r.get('user:'+today),)
print a
print a.count()

if __name__=='__main__':
setup()
setuniquser(uid=0)
countuniquser()

11.維護好友關系

使用set進行是否為好友關系,共同好友等操作

12.使用 Redis 實現(xiàn)自動補全功能

使用有序集合保存輸入結果:

ZADD word:a 0 apple 0 application 0 acfun 0 adobe
ZADD word:ap 0 apple 0 application
ZADD word:app 0 apple 0 application
ZADD word:appl 0 apple 0 application
ZADD word:apple 0 apple
ZADD word:appli 0 application

再使用一個有序集合保存熱度:

ZADD word_scores 100 apple 80 adobe 70 application 60 acfun

取結果時采用交集操作:

ZINTERSTORE word_result 2 word_scores word:a WEIGHTS 1 1
ZRANGE word_result 0 -1 withscores

13. 可靠隊列設計

? UUIDs as Surrogate Keys Our strategy spreads information about the state of an item in the queue across a number of Redis data structures, requiring the use of a per-item surrogate key to tie them together. The UUID is a good choice here because 1) they are quick to generate, and 2) can be generated by the clients in a decentralized manner. ? Pending List The Pending List holds the generated UUIDs for the items that have been enqueued(), and are ready to be processed. It is a RedisList, presenting the generated UUIDs in FIFO order. ? Values Hash The Values Hash holds the actual items that have been enqueued. It is a Redis Hash, mapping the generated UUID to the binary form of the the item. This is the only representation of the original item that will appear in any of the data structures. ? Stats Hash The Stats Hash records some timestamps and counts for each of the items. Specifically: ? enqueue time ? last dequeue time ? dequeue count ? last requeue time ? last requeue count. It is a Redis Hash, mapping the generated UUID to a custom data structure that holds this data in a packed, binary form. Why keep stats on a per-item basis? We find it really useful for debugging (e.g. do we have a bad apple item that is being continuously requeued?), and for understanding how far behind we are if queues start to back up. Furthermore, the cost is only ~40 bytes per item, much smaller than our typical queued items. ? Working Set The Working Set holds the set of UUIDs that have been dequeued(), and are currently being processed. It is a Redis Sorted Set, and scores each of the UUIDs by a pre-calculated, millisecond timestamp. Any object that has exceeded its assigned timeout is considered abandoned, and is available to be reclaimed. ? Delay Set The Delay Set holds the set of UUIDs that have been requeued() with a per-item deferment. It is a Redis Sorted Set, and scores each of the UUIDs by a pre-calculated, millisecond timestamp. Once the deferment timestamp has expired, the item will be returned to the Pending List. Why support per-item deferment? We have a number of use cases where we might want to backoff specific pieces of work — maybe an underlying resource is too busy — without backing off the entire queue. Per-item deferment lets us say, “requeue this item, but don’t make it available for dequeue for another n seconds.”