引自:http://blog.csdn.net/chosen0ne/article/details/7319807python
import redis r = redis.StrictRedis(host='127.0.0.1', port=9212) r.set('foo', 'hello') r.rpush('mylist', 'one') print r.get('foo') print r.rpop('mylist')
import redis pool = redis.ConnectionPool(host='127.0.0.1', port=9212) r = redis.Redis(connection_pool=pool) r.set('one', 'first') r.set('two', 'second') print r.get('one') print r.get('two')
3.redis pipeline機制,能夠在一次請求中執行多個命令,這樣避免了屢次的往返時延。redis
import redis pool = redis.ConnectionPool(host='127.0.0.1', port=9212) r = redis.Redis(connection_pool=pool) pipe = r.pipeline() pipe.set('one', 'first') pipe.set('two', 'second') pipe.execute() pipe.set('one'. 'first').rpush('list', 'hello').rpush('list', 'world').execute()
pipe = r.pipeline(transaction=False)