現狀:
1、買了一台主從的阿里雲Redis,內存就1GB。
2、查詢了阿里雲的幫助,沒有找到性能相關的說明, 有的也是4GB版本的並發性能
3、提工單問客服 一個集合里有300萬數據,單次查詢性能大概怎么推算,客服讓我自己驗證(自己的產品性能如何都不知道,還賣貨……)
解決方案:自己驗證
1、構造300萬數據, 寫到文件1.txt,將數據寫入到集合test500內
sadd test500 long_str10000001
sadd test500 long_str10000002
...
...
sadd test500 long_str13000000
2、在windows電腦上安裝redis客戶端,並通過命令管道快速導入這300萬條命令(不帶pipe,只能做到1小時導入30萬條;帶pipe就十幾秒鍾導入完成)
redis-cli -h xxx.redis.rds.aliyuncs.com -p 6379 -a password --pipe <1.txt
3、在python中調用查詢某個value,響應時間為0.04~0.08秒 【包括了網絡響應的時長】
# -*- coding: utf-8 -*- import time import redis class T: def __init__(self): pool = redis.ConnectionPool(host='r-xxx.redis.rds.aliyuncs.com', port=6379, password='xxx', db=1, decode_responses=True) self.r = redis.Redis(connection_pool=pool) self.value = 'long_str10000001' if __name__ == '__main__': t = T() time_begin = time.clock() qq = t.r.sismember('test500', 'long_str10031001') time_end = time.clock() time2 = time_end - time_begin if qq: print("數據查詢成功,耗時", time2) else: print("數據查詢失敗,耗時", time2)
結論:Redis的某一個集合,放百萬數據,查詢性能毫無影響。
遺留問題:
該集合是300萬數據,每條數據16個字節,數據大小是45M左右,而存放到了阿里雲的Redis,占用了200MB空間,這個不符合我的訴求; 需要后期上其他方案,降低內存的占用
