用python訪問redis的幾種常用方式

1,配置sentinel

創(chuàng)新互聯(lián)建站主要從事成都網(wǎng)站設(shè)計、網(wǎng)站制作、網(wǎng)頁設(shè)計、企業(yè)做網(wǎng)站、公司建網(wǎng)站等業(yè)務(wù)。立足成都服務(wù)甕安,十多年網(wǎng)站建設(shè)經(jīng)驗,價格優(yōu)惠、服務(wù)專業(yè),歡迎來電咨詢建站服務(wù):18982081108

from redis.sentinel import Sentinel

sentinel = Sentinel([('192.168.0.210', 26379),('192.168.1.220', 26380),('192.168.1.220', 26379)], socket_timeout=0.1)
master = sentinel.master_for('mymaster',password='admin')
slave = sentinel.slave_for('mymaster',password='admin')
master.sadd('s4',1,2,3,4)
print master.smembers('s4')

2,直連 redis

pool = redis.ConnectionPool(host='127.0.0.1', port=6379, password='admin',db=0)
r = redis.Redis(connection_pool=pool)

3,連接 redis cluster

from rediscluster import StrictRedisCluster

redis_nodes = [{'host':'192.168.1.210','port':3790},
{'host':'192.168.1.210','port':3791},
{'host':'192.168.1.210','port':3793},
{'host':'192.168.1.220','port':3794},
{'host':'192.168.1.220','port':3795},
{'host':'192.168.1.220','port':3796}
]
redisconn = StrictRedisCluster(startup_nodes=redis_nodes,decode_responses=True,password='admin')

本文標(biāo)題:用python訪問redis的幾種常用方式
瀏覽路徑:http://bm7419.com/article26/iicojg.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供網(wǎng)站營銷、企業(yè)建站網(wǎng)站內(nèi)鏈、移動網(wǎng)站建設(shè)、關(guān)鍵詞優(yōu)化、建站公司

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)

搜索引擎優(yōu)化