虽然有set和get操作,但是一个一个的操作终究还是麻烦,所以,我们还有mset和mget命令
python在进行mset操作时,只需要传入一个dict即可,进行mget操作,则传入一个list
看代码
# coding=utf-8
'''
Created on 2015-9-8
@author: kwsy
'''
import redis
import datetime
import time
pool=redis.ConnectionPool(host='192.168.1.126',port=6379,db=0)
r = redis.StrictRedis(connection_pool=pool)
keydict = {}
keydict['key1'] = 324
keydict['key2'] = 'ag'
print r.mset(keydict)
list = ['key1','key2']
print r.mget(list)