python中使用redis测试代码:
import redis # redis 测试代码
pool = redis.ConnectionPool(host='192.168.0.148', port=6379, db=0, password='123456')
def main():
redis2.ThreadRun()
print('main()')
if __name__ == '__main__':
main()
def test():
r = redis.Redis(connection_pool=pool)
r.set('k1', '12')
r.set('k2', '23')
print(r.get('k1'))
r.close()
# print(r.keys()) #打印当前所有的keys
# print(r.dbsize()) #查看当前有多少keys
# r.delete('k2') #删除k2
# print(r.keys())
# print(r.dbsize())
# print(dir(r)) #查看redis对应的方法
# #pipeline
# p = r.pipeline()
# p.set('k3', 'v3')
# p.set('k4', 'v4')
# p.execute()
# print(r.get('num'))