First turn on Redis's external connection
[Email protected]:~$ sudo vim/etc/redis/redis.conf
Comment out the bind 127.0.0.1.
Then restart Redis
Sudo/etc/init.d/redis-server restart
This way, the Ubuntu Redis machine can be connected
Connect and manipulate
#-*-Coding:utf-8-*-__author__ = "MuT6 sch01ar" Import Redisr = Redis. Redis (host= ' 192.168.220.144 ', port=6379) r.set (' name ', ' John ') print (R.get (' name '))
Run results
Results of Redis on Ubuntu
Connection pool
Python operation Redis, the operation once requested a connection, the operation is completed disconnect, the connection pool to the Redis connection request into the pool, easy to operate, to avoid each establishment, release the cost of the connection
#-*-Coding:utf-8-*-__author__ = "MuT6 sch01ar" Import Redispool = Redis. ConnectionPool (host= ' 192.168.220.144 ', port=6379) R = Redis. Redis (Connection_pool=pool) r.set (' age ', *) print (R.get (' age '))
Run results
Results of Redis on Ubuntu
Pipeline
Execute multiple commands in a single request, you can use the pipeline implementation to execute multiple commands in a single request
#-*-Coding:utf-8-*-__author__ = "MuT6 sch01ar" Import Redispool = Redis. ConnectionPool (host= ' 192.168.220.144 ', port=6379, db=2) R = Redis. Redis (connection_pool=pool) pipe = R.pipeline (transaction=true) pipe.set (' name ', ' John ') pipe.set (' age ', 22) Pipe.execute ()
Run results
python-Connect to Redis and operate