如何在Python配置复述,连接

  介绍

这期内容当中小编将会给大家带来有关如何在Python配置复述,连接,文章内容丰富且以专业的角度为大家分析和叙述,阅读完这篇文章希望大家可以有所收获。

Python主要用来做什么

Python主要应用于:1,网络开发;2、数据科学研究;3,网络爬虫;4、嵌入式应用开发,5日游戏开发;6桌面应用开发。

系统环境:

操作系统:甲骨文Linux Enterprise 5.6

复述:redis-2.6.8

Python: Python-2.7.3

复述的Python包版本:redis-2.7.2.tar

前提条件:

1。确保复述,已成功安装并且正确配置,参考文档

主从配置文档:

//www.jb51.net/article/147397.htm

2。确保Python环境已成功配置,参考文档https://www.jb51.net/article/109765.htm

配置Python连接复述:

<强> 1。安装复述的Python包:

使用容易的安装安装,关于容易的安装的配置,参考以Python上环境的搭建。

[root@njdyw 本]#,easy_install2.7.3 复述   Searching  for 复述   Reading  http://pypi.python.org/simple/redis/Reading  http://github.com/andymccurdy/redis-py   Best 匹配:redis  2.7.2   Downloading  http://pypi.python.org/packages/source/r/redis/redis-2.7.2.tar.gz md5=17 ac60dcf13eb33f82cc25974ab17157   Processing  redis-2.7.2.tar.gz   Running  redis-2.7.2/setup.py  -q  bdist_egg ——dist-dir /tmp/easy_install-8FAlft/redis-2.7.2/egg-dist-tmp-JzQViJ   zip_safe  flag  not 设置,analyzing  archive 内容…   Adding  redis  2.7.2 用easy-install.pth 文件   ,   Installed /usr/地方/python2.7.3/lib/python2.7/网站/redis-2.7.2-py2.7.egg   Processing  dependencies  for 复述   Finished  processing  dependencies  for 复述,

<强>安装解析器包(可选)

说明:解析器可以控制如何解析复述,响应的内容.redis-py包含两个解析器类,PythonParser和HiredisParser。默认,如果已经安装了hiredis模块,redis-py会使用HiredisParser,否则会使用PythonParser。

HiredisParser是C编写的,由复述,核心团队维护,性能要比PythonParser提高10倍以上,所以推荐使用。安装方法,使用easy_install:

[root@njdyw  ~] #, easy_install2.7.3  hiredis   Searching  for  hiredis   Reading  http://pypi.python.org/simple/hiredis/Reading  https://github.com/pietern/hiredis-py   Best 匹配:hiredis  0.1.1   Downloading  http://pypi.python.org/packages/source/h/hiredis/hiredis-0.1.1.tar.gz md5=92128474 f6fb027cfb8587fce724ea8e   Processing  hiredis-0.1.1.tar.gz   Running  hiredis-0.1.1/setup.py  -q  bdist_egg ——dist-dir /tmp/easy_install-ZanSCB/hiredis-0.1.1/egg-dist-tmp-XCZBQ0   zip_safe  flag  not 设置,analyzing  archive 内容…   Adding  hiredis  0.1.1 用easy-install.pth 文件   ,   Installed /usr/地方/python2.7.3/lib/python2.7/网站/hiredis-0.1.1-py2.7-linux-x86_64.egg   Processing  dependencies  for  hiredis   Finished  processing  dependencies  for  hiredis

<强> 2。检查安装是否成功

——容易的安装安装的扩展包默认在python的网站目录下

[root@njdyw  ~] # whereis  python2.7.3   python2.7:/bin/python2.7.3 /usr/地方/python2.7.3   (root@njdyw  ~) # cd /usr/地方/python2.7.3/lib/python2.7/网站/[root@njdyw 网站]#,你

总计408

-rw-r——r, 1, root  root , 239, 03-21  10:45  easy-install.pth   -rw-r——r, 1, root  root , 119, 03-21  10:07  README   -rw-r——r, 1, root  root  60401, 03-21  10:45redis-2.7.2-py2.7.egg   -rw-r——r, 1, root  root  332125, 03-21  setuptools 10:12  0.6 - c11 py2.7.egg   -rw-r——r, 1, root  root ,, 30, 03-21  10:12  setuptools.pth

可以看到redis-2.7.2-py2.7.egg包已经成功安装

<强> 3。测试连接

# python2.7.3 root@njdyw 网站   Python  2.7.3 (默认情况下,,Mar  21, 2013年,10:06:48)   [GCC  4.1.2  20080704, (Red  Hat  4.1.2-50)],提醒linux2   想Type “帮助”,,“copyright",,“credits",趁机“license" for  more 信息。   在祝辞祝辞import 复述   祝辞祝辞祝辞redisClient=redis.StrictRedis(主机=& # 39;127.0.0.1 # 39;,端口=6379,德国联邦铁路(db)=0)   祝辞祝辞祝辞,redisClient.set (& # 39; test_redis& # 39; & # 39; Hello  python # 39;)   真正的   在祝辞祝辞,value=https://www.yisu.com/zixun/redisClient.get (“test_redis”)>>打印值   你好Python>> redisClient.delete (“test_redis”)   真正的>>价值=redisClient.get (“test_redis”)>>打印值   没有一个>> dir(复述)   [‘AuthenticationError’,‘联系’,‘ConnectionError’,‘ConnectionPool’,‘DataError’,‘InvalidResponse’,‘PubSubError’,“复述”,‘RedisError’,‘ResponseError’,‘StrictRedis’,‘UnixDomainSocketConnection’,“版本”,‘WatchError’,‘__all__’,‘__builtins__’,‘__doc__’,‘__file__’,‘__loader__’,‘__name__’,‘__package__’,‘__path__’,‘__version__’,‘_compat’,‘客户’,‘联系’,‘异常’,‘from_url’,“跑龙套”)>> redisClient=redis.StrictRedis(主机=127.0.0.1,端口=6379,德国联邦铁路(db)=0)   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null

如何在Python配置复述,连接