python3_redis随手学习笔记
#!/usr/bin/python #-*- coding:utf-8 -*- # by zmoke import redis import json #使用redis pool pool = redis.ConnectionPool(host="*",port=6379,password='*') r = redis.Redis(connection_pool=pool) #直接连接使用api # r = redis.Redis(host='*',port=6379,password='*') print(r.keys()) #info 指定参数 print(r.info(section='clients')) print(r.info(section='Keyspace')) #info 不指定参数,默认所有信息 # print(r.info()) # getset() 方法,返回旧值,同时赋洗你的值 r.set('test',1111) print(r.get('test')) r.getset('test','this is new value') print(r.get('test')) #getrang() 子串(偏移量:offset: 0代表开始,-1代表结束) print(r.getrange('test',-3,-1)) #setrange()替换子串(从偏移量开始) r.setrange('test',0,'change') print(r.get('test')) #mset()一次设置多个键的值 r.mset({'pig':'111','ca':'222','app':'333'}) print(r.info(section='Keyspace')) #mget()一次取多个键的值 print(r.mget(['pig','app'])) #delete 删除键 r.delete('pig') print(r.get('pig')) #批量删除 DelList=r.keys('*') for key in DelList: r.delete(key)
当前名称:python3_redis随手学习笔记
转载源于:http://ybzwz.com/article/igeepj.html