远程服务器,redis 安装在/opt下redis-4.0.10python
cd redis-4.0.10redis
修改配置文件redis.conf配置文件:(注释掉bind:127.0.0.1)和修改保护模式为no数据库
修改另外一个配置文件:vim
vim redis-6379.conf,修改保护模式:服务器
启动redis服务url
redis-server redis-6379.confspa
进入redis 客户端code
redis-cliserver
# coding=utf8 """ author:dengjiyun """ import redis pool=redis.ConnectionPool(host='182.61.24.122',port=6379) r =redis.Redis(connection_pool=pool) # 从数据库中获取数据 name=r.get('name').decode('utf-8') print(name)
# coding=utf8 """ author:dengjiyun """ import redis pool=redis.ConnectionPool(host='182.61.24.122',port=6379) r =redis.Redis(connection_pool=pool) # set 集合 res=r.sadd('url_set','url1') # 当res=1,表示要添加的url不在 url_set 中 当res=0 时表示url已经存在url_set 从而实现去重的功能 if res: print('新添加成功!') # 此处可让把该url直接让爬虫进行爬取 else: print('该url已经存在')