One, the Mac under Redis installation
1. Brew Installation Redis
Brew Install Redis
2. Start Redis Server
Brew Services Start Redis
Or
Redis-server/usr/local/etc/redis.conf
Second, Python operation Redis
1. Connection mode
Redis-py provides two classes of Redis and Strictredis for implementing Redis commands, Strictredis is used to implement most of the official commands, and using official syntax and commands, Redis is a subclass of Strictredis
#!/usr/bin/env python#-*-coding:utf-8-*-import redisr = Redis. Redis (host= ' 192.168.0.110 ', port=6379,db=0) r.set (' name ', ' Zhangsan ') #添加print (r.get (' name ')) #获取
2. Connection Pool
Redis-py uses connection pool to manage all connections to a Redis server, avoiding the overhead of each establishment and release of the connection. By default, each Redis instance maintains its own pool of connections. You can create a connection pool directly, and then as a parameter Redis, you can implement multiple Redis instances to share a single connection pool.
#!/usr/bin/env python#-*-coding:utf-8-*-import redispool = Redis. ConnectionPool (host= ' 192.168.0.110 ', port=6379) R = Redis. Redis (Connection_pool=pool) r.set (' name ', ' Zhangsan ') #添加print (r.get (' name ')) #获取
How to use Python Redis