python2.7连接操作redis的几种方法-创新互联
pyth成都创新互联公司是一家集网站建设,双阳企业网站建设,双阳品牌网站建设,网站定制,双阳网站建设报价,网络营销,网络优化,双阳网站推广为一体的创新建站企业,帮助传统企业提升企业形象加强企业竞争力。可充分满足这一群体相比中小企业更为丰富、高端、多元的互联网需求。同时我们时刻保持专业、时尚、前沿,时刻以成就客户成长自我,坚持不断学习、思考、沉淀、净化自己,让我们为更多的企业打造出实用型网站。on版本:2.7
首先需要先安装redis模块:
wget https://pypi.python.org/packages/source/r/redis/redis-2.10.3.tar.gz
tar zxvf redis-2.10.3.tar.gz
cd redis-2.10.3
python setup.py install
备注:安装方法可以参考INSTALL文件内容
#cat INSTALL
Please use
python setup.py install
and report errors to Andy McCurdy (sedrik@gmail.com)
然后开始导入redis模块
[root@test ~/python]#python
Python 2.7.12 (default, Jun 1 2018, 14:00:01)
[GCC 4.4.7 20120313 (Red Hat 4.4.7-18)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import redis
>>>
以下是操作redis的四种方法:
#cat 1.py
#encoding=utf-8
import redis
r = redis.StrictRedis(host='localhost', port=6379)
print r.ping()
#cat 2.py
#encoding=utf-8
import redis
r = redis.StrictRedis(host='127.0.0.1', port=6379, db=0)
print r.ping()
#cat 3.py
#encoding=utf-8
import redis
pool = redis.ConnectionPool(host='localhost', port=6379, decode_responses=True)
r = redis.Redis(connection_pool=pool)
print r.ping()
#cat 4.py
# -*- encoding: UTF-8 -*-
import redis
r = redis.Redis(host='localhost', port=6379, decode_responses=True)
print r.ping()
分享名称:python2.7连接操作redis的几种方法-创新互联
网页地址:http://myzitong.com/article/dcpsid.html
首先需要先安装redis模块:
wget https://pypi.python.org/packages/source/r/redis/redis-2.10.3.tar.gz
tar zxvf redis-2.10.3.tar.gz
cd redis-2.10.3
python setup.py install
备注:安装方法可以参考INSTALL文件内容
#cat INSTALL
Please use
python setup.py install
and report errors to Andy McCurdy (sedrik@gmail.com)
然后开始导入redis模块
[root@test ~/python]#python
Python 2.7.12 (default, Jun 1 2018, 14:00:01)
[GCC 4.4.7 20120313 (Red Hat 4.4.7-18)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import redis
>>>
以下是操作redis的四种方法:
#cat 1.py
#encoding=utf-8
import redis
r = redis.StrictRedis(host='localhost', port=6379)
print r.ping()
#cat 2.py
#encoding=utf-8
import redis
r = redis.StrictRedis(host='127.0.0.1', port=6379, db=0)
print r.ping()
#cat 3.py
#encoding=utf-8
import redis
pool = redis.ConnectionPool(host='localhost', port=6379, decode_responses=True)
r = redis.Redis(connection_pool=pool)
print r.ping()
#cat 4.py
# -*- encoding: UTF-8 -*-
import redis
r = redis.Redis(host='localhost', port=6379, decode_responses=True)
print r.ping()
分享名称:python2.7连接操作redis的几种方法-创新互联
网页地址:http://myzitong.com/article/dcpsid.html