python connection redis storage

The first is to install redis friends. This reference online article. He said fairly detailed.

But let me into a lot of the pit, that is, when the external network connection redis, always disconnect the positive, I thought it was a firewall problem, then check the information to know, because the default configuration file is not allowed redis external network access.

https://www.cnblogs.com/zuidongfeng/p/8032505.html

Easy installation refer to this article now.

Which says how to set up way back redis redis start there and start adding boot, and so on. I command lazy and do not fight.

Another article that is redis set the access password.

https://www.cnblogs.com/yanggb/p/11361991.html

This article is also good. Redis to set up.

redis commonly used commands. redis-cli into the command line

        View all key keys *

        set key value [EX seconds] [PX milliseconds] [NX | XX] settings are stored inside the EX is the number of seconds

        get key value can be displayed

Then redis is set outside the network visit.

https://www.cnblogs.com/grimm/p/11133226.html   reference to this.

Provided that you have put into port redis firewall program,

/sbin/iptables -I INPUT -p tcp --dport 6379 -j ACCEPT

/etc/rc.d/init.d/iptables save

changes redis.conf file

bind 127.0.0.1

protected-mode yes

Change

# bind 127.0.0.1

protected-mode no

set password

Requirepass foobared # 
requirepass yourpassword // Note here that can not have spaces forward

Then restart redis,
provided that you are now running redis
closed redis

Redis-cli the shutdown #

redis-cli is your installation path, that is, make install, you specify a path,
restart redis

Server-/opt/local/redis/redis-4.0.6/redis.conf Redis

Redis-Server is also installed in the path
so that access is provided outside the network is successful.
------------ ---------

 

Then configure the redis be successful. This can be used to connect to the python.

code show as below:

# _ * _ Coding: UTF-_ * _. 8 
# author: david.z 

Import Redis 
PASSWORD = ' 123 ' 
# RES = redis.Redis (= Host 'you the IP', Port = 6379, password = PASSWORD) 
RES = Redis. StrictRedis (Host = 'you the IP ' , password = pASSWORD, DB =. 3, Port = 6379, decode_responses = True) # decoded and to be stored Chinese 
Print (RES) # this is a single redis connection 
# Print (the dir (redis )) 
res.set ( ' foo ' , ' I love you, China ' )
 Print (res.get ( ' foo ' ))

the pool = redis.ConnectionPool (= Host 'you the IP ' , password = PASSWORD, DB =. 3, Port = 6379, decode_responses = True)
 Print (the pool) # This is a connection pool 
R & lt redis.Redis = (= connection_pool the pool) 
r.set ( ' foo ' , ' I love you Beijing ' )
 Print (r.get ( ' foo ' ))

 

Guess you like

Origin www.cnblogs.com/davidz/p/12318897.html