1、scan_iter
car_key = 'shopping*' # print(car_key) data_li = [] for i in con.scan_iter(car_key): # print(i) # print(con.hget(i, 'title')) # print(con.hget(i, 'img')) val = con.hgetall(i) info = { 'title': con.hget(i, 'title').decode('utf-8'), 'img': con.hget(i, 'img').decode('utf-8') } data_li.append(info) print(data_li)
scan_iter与hscan_iter的区别
sacn_iter 遍历的是 name(name)
hscan_iter变量的是字典(5中基础数据类型)
for i in con.hscan_iter(redis_key3): print(i)
2、delete
con.delete(redis_key3)
delete删除的是key(name)
hdel删除的是value
# con.hdel(redis_key3, 'title') val = con.hgetall(redis_key3) print(val)
3、flushall
con.flushall() # 清空所有数据=》redis
4、expire
超时设置,超过一定的时间消失(内存空间有限)
con.expire(redis_key3, 60*2) # 120秒后过期
扫描二维码关注公众号,回复:
7351452 查看本文章
![](/qrcode.jpg)