Python爬虫学习笔记(Redis 存储)

1.连接Redis数据库,设置、读入数据

from redis import StrictRedis,ConnectionPool

url = 'redis://:lj960802@localhost:6379/0' #密码@地址:端口/数据库
pool = ConnectionPool.from_url(url)
redis =StrictRedis(connection_pool=pool)
redis.set('Sex','Male')
print(redis.get('Sex'))

2.Redis键的判断和操作方法:请参考本篇博客

3.RedisDump

导出数据:redis-dump:

redis-dump -h:查看所有可选项

导出数据:redis-dump -u :password@localhost:port(默认6379)

导出为JSON行文件:redis-dump -u :password@localhost:port>./redis_data.jl

指定数据库我的所有数据导出:redis-dump -u :password@localhost:port -d BaseName>./redis_data.jl

添加过滤规则:redis-dump -u :password@localhost:port -f adsl:*>./redis_data.jl

导入数据:redis-load

  redis-load -h:查看所有可选项

导入JSON行文件:<redis_data.json redis-load -u :password@localhost:port>

发布了48 篇原创文章 · 获赞 19 · 访问量 1万+

猜你喜欢

转载自blog.csdn.net/qq_33360009/article/details/104334433