- 下载Redis
- 配置Redis
sudo vim /etc/redis/redis.conf
修改bind行,将127.0.0.1修改为*,配置远程可以访问
- ubuntu启动Redis服务
service redis-server start
service redis-server status
- 以命令行方式进入Redis,分别为本地进入方式与远程进入方式:
redis-cli
redis-cli -h 10.108.115.229 -p 6379
- 命令行查看:SMEMBERS HTTP_RESULT
- 命令行删除:del HTTP_RESULT
python发送redis示例
import redis
import json
pool= redis.ConnectionPool(host='10.108.114.100',port=6379,decode_responses=True)
r=redis.Redis(connection_pool=pool)
msg = {"agent_id": "000",
"task_id": "72fb264dd882958ac70045ab6ffe41d4",
"src_path": "/http-data/copy_file/2018-09-13/10.3.200.155/",
"upload_host": "10.3.200.155",
"target_path": "",
"status": 1,
"copy_file_size": 0,
"yesterday": "2018-09-13",
"msg": "",
"time": {"start_time": "2018-09-13 14:30:41",
"copy_finish_time": "2018-09-13 14:30:41",
"write_HDFS_finish_time": "2018-09-13 14:31:02"}
}
js = json.dumps(msg)
r.sadd('HTTP_RESULT',js)
python接收redis示例
# redis通信控制
pool= redis.ConnectionPool(host=redis_host,port=redis_port,decode_responses=True)
r=redis.Redis(connection_pool=pool)
tmp = r.spop('HTTP_DL_QUEUE')
ob_js = json.loads(tmp)
src_hdfs_path = ob_js["src_path"]
task_id = ob_js["task_id"]
agent_id = ob_js["agent_id"]