设置redis能远程访问
生活随笔
收集整理的這篇文章主要介紹了
设置redis能远程访问
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
遠程服務器,redis 安裝在/opt下redis-4.0.10
cd redis-4.0.10
修改配置文件redis.conf配置文件:(注釋掉bind:127.0.0.1)和修改保護模式為no
修改另一個配置文件:
?vim? redis-6379.conf,修改保護模式:
啟動redis服務
redis-server redis-6379.conf
進入redis 客戶端
redis-cli
?python 中操作redis
# coding=utf8 """ author:dengjiyun """ import redispool=redis.ConnectionPool(host='182.61.24.122',port=6379)r =redis.Redis(connection_pool=pool)# 從數據庫中獲取數據 name=r.get('name').decode('utf-8')print(name)?利用redis中set集合進行去重url
# coding=utf8 """ author:dengjiyun """ import redispool=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已經存在')?
轉載于:https://www.cnblogs.com/knighterrant/p/10921923.html
總結
以上是生活随笔為你收集整理的设置redis能远程访问的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 8、python基础知识-用户输入
- 下一篇: 利用ansible 自动发布安装