温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

python3_redis随手学习笔记

发布时间:2020-06-19 23:28:46 来源:网络 阅读:735 作者:zmoke 栏目:编程语言
#!/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)


向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI