安装
apt-get install redis-server
apt-get install python-redis
配置
允许从远程连接,修改配置文件/etc/redis/redis.conf
注释bind这一行
#bind 127.0.0.1
然后重启redis-server服务生效
测试
root@h1:~# redis-cli
127.0.0.1:6379> ping
PONG
127.0.0.1:6379> keys *
(empty list or set)
127.0.0.1:6379> set cpu 60
OK
127.0.0.1:6379> set mem 70
OK
127.0.0.1:6379> keys *
1) "mem"
2) "cpu"
127.0.0.1:6379> get cpu
"60"
127.0.0.1:6379> get mem
"70"
127.0.0.1:6379> del cpu
(integer) 1
从远程连接的命令行形式
redis-cli -h [target-ip]
通过Pythong调用
python
>>> import redis
>>> db.keys()
['io']
>>> db.set('cpu', 30)
True
>>> db.get('cpu')
'30'
>>> db.keys()
['cpu', 'io']
>>> db.delete('cpu')
1
>>> db.keys()
['io']