python连接redis的三种方式

今天就给大家分享一下python连接redis的几种操作

# Connection redis function

#   the first Connection redis way
import redis
redis_conn = redis.Redis(host="localhost", port=6379, decode_responses=True)

#   the second Connection redis way
from redis import StrictRedis
redis_conn = StrictRedis(host="localhost", port=6379, password="123456")

#   the third Connection redis way

from redis import StrictRedis, ConnectionPool
pool = ConnectionPool(host="localhost", port=6370, db=0, password="2342")
redis = StrictRedis(connection_pool=pool)

# other Connection redis way
url = 'redis://:foobared@localhost:6379/0'
pool = ConnectionPool.from_url(url)
redis = StrictRedis(connection_pool=pool)

你可能感兴趣的:(redis,数据库,java)