yasmine_yang

导航

Redis连接方式

连接redis

本地安装了Redis并运行在6379端口,密码设置为 foobared. 

1.

from redis import StrictRedis

redis = StrictRedis(host='localhost',port=6379,db=0,password='foobared')

注释:db是数据库名称

2.

from redis import StrictRedis,ConnectionPool

pool = ConnectPool(host='localhost',port = 6379,db=0,password='foobared')

redis = StrictRedis(connection_pool=pool)

3.

redis://[:password]@host:port/db

rediss://[:password]@host:port/db

unix://[:password]/path/to/socket.sock?db=db

 

url='redis://foobared@localhost:6379/0'

pool = ConnectionPool.from_url(url)

redis=StrictRedis(connection_pool=pool)

 

posted on 2019-01-07 10:57  yasmine_yang  阅读(8236)  评论(0编辑  收藏  举报