linux与python3安装redis

1、linux安装redis服务

apt-get install redis*

进入客户端管理

redis-cli

启动服务

service redis start
service redis restart
service redis stop

 

2、python安装redis模块

Python默认是不支持Redis的,当引用redis时就会报错:

1)、下载redis安装包安装

这里需要为Python安装Redis库,下载https://github.com/andymccurdy/redis-py 后,解压并安装:

unzip redis-py-master.zip -d /usr/local/redis
cd /usr/local/redis
cd redis-py-master/
sudo python setup.py install

 

2)、pip安装

pip install redis
pip3 install redis

 

安装完进行测试

root@raspberrypi:~# python3
Python 3.5.3 (default, Jan 19 2017, 14:11:04)
[GCC 6.3.0 20170124] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import redis
>>> r = redis.Redis(host='localhost',port=6379,db=0)
>>> r.set('foo','bar')
True
>>> r.get('foo')
b'bar'
>>> exit()

 

posted @ 2018-10-16 11:08  m0w3n  阅读(5799)  评论(0编辑  收藏  举报