默认redis模块没有安装,安装方式很多种,下面只介绍一种最简单的:
[root@tom]# yum list | grep python | grep redis
python-redis.noarch 2.0.0-1.el6 @epel
[root@tom]# yum install python-redis
Loaded plugins: fastestmirror, security
Loading mirror speeds from cached hostfile
Setting up Install Process
Resolving Dependencies
--> Running transaction check
---> Package python-redis.noarch 0:2.0.0-1.el6 will be installed
--> Finished Dependency Resolution
Dependencies Resolved
===============================================================================================================================================================================================
Package Arch Version Repository Size
===============================================================================================================================================================================================
Installing:
python-redis noarch 2.0.0-1.el6 epel 30 k
Transaction Summary
===============================================================================================================================================================================================
Install 1 Package(s)
Total download size: 30 k
Installed size: 116 k
Is this ok [y/N]: y
Downloading Packages:
python-redis-2.0.0-1.el6.noarch.rpm | 30 kB 00:00
Running rpm_check_debug
Running Transaction Test
Transaction Test Succeeded
Running Transaction
Installing : python-redis-2.0.0-1.el6.noarch 1/1
Verifying : python-redis-2.0.0-1.el6.noarch 1/1
Installed:
python-redis.noarch 0:2.0.0-1.el6
Complete!
redis模块可以使用了。
[root@tom]# ptyhon
[GCC 4.4.7 20120313 (Red Hat 4.4.7-4)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import redis
>>> r = redis.Redis(host='localhost',port=6479)
>>> r.get('hello')
>>> world