Python连接Redis配置详解
Python连接Redis配置详解
操作环境: CentOS 5.4
操作步骤:
(一) 安装Redis:
[plain]
[root@localhost /]# yum install redis
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
* base: centos.ustc.edu.cn
* epel: mirrors.yun-idc.com
* extras: mirrors.yun-idc.com
* updates: mirrors.yun-idc.com
Setting up Install Process
Resolving Dependencies
--> Running transaction check
---> Package redis.i386 0:2.4.10-1.el5 set to be updated
--> Finished Dependency Resolution
Dependencies Resolved
================================================================================
Package Arch Version Repository Size
================================================================================
Installing:
redis i386 2.4.10-1.el5 epel 299 k
Transaction Summary
================================================================================
Install 1 Package(s)
Upgrade 0 Package(s)
Total download size: 299 k
Is this ok [y/N]: y
Downloading Packages:
redis-2.4.10-1.el5.i386.rpm | 299 kB 00:01
Running rpm_check_debug
Running Transaction Test
Finished Transaction Test
Transaction Test Succeeded
Running Transaction
Installing : redis 1/1
Installed:
redis.i386 0:2.4.10-1.el5
Complete!
[root@localhost /]# yum install redis
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
* base: centos.ustc.edu.cn
* epel: mirrors.yun-idc.com
* extras: mirrors.yun-idc.com
* updates: mirrors.yun-idc.com
Setting up Install Process
Resolving Dependencies
--> Running transaction check
---> Package redis.i386 0:2.4.10-1.el5 set to be updated
--> Finished Dependency Resolution
Dependencies Resolved
================================================================================
Package Arch Version Repository Size
================================================================================
Installing:
redis i386 2.4.10-1.el5 epel 299 k
Transaction Summary
================================================================================
Install 1 Package(s)
Upgrade 0 Package(s)
Total download size: 299 k
Is this ok [y/N]: y
Downloading Packages:
redis-2.4.10-1.el5.i386.rpm | 299 kB 00:01
Running rpm_check_debug
Running Transaction Test
Finished Transaction Test
Transaction Test Succeeded
Running Transaction
Installing : redis 1/1
Installed:
redis.i386 0:2.4.10-1.el5
Complete! (二)启动redis:
[plain]
[root@localhost etc]# redis-server /etc/redis.conf
[root@localhost etc]# ps -ef | grep redis
root 17699 1 0 12:05 ? 00:00:00 redis-server /etc/redis.conf
root 17762 17615 0 12:49 pts/1 00:00:00 grep redis
[root@localhost etc]# redis-server /etc/redis.conf
[root@localhost etc]# ps -ef | grep redis
root 17699 1 0 12:05 ? 00:00:00 redis-server /etc/redis.conf
root 17762 17615 0 12:49 pts/1 00:00:00 grep redis (三)用telnet连接并测试:
[plain]
[root@localhost etc]# telnet localhost 6379
Trying 127.0.0.1...
Connected to localhost.localdomain (127.0.0.1).
Escape character is '^]'.
set key1 4
+OK
get key1
$1
4
set key2 hello
+OK
get key2
$5
hello
quit
+OK
Connection closed by foreign host.
[root@localhost etc]# telnet localhost 6379
Trying 127.0.0.1...
Connected to localhost.localdomain (127.0.0.1).
Escape character is '^]'.
set key1 4
+OK
get key1
$1
4
set key2 hello
+OK
get key2
$5
hello
quit
+OK
Connection closed by foreign host. (四)安装python client:
[plain]
[root@localhost etc]# easy_install redis
Searching for redis
Reading http://pypi.python.org/易做图/redis/
Best match: redis 2.7.6
Downloading https://pypi.python.org/packages/source/r/redis/redis-2.7.6.tar.gz#md5=e975ea446c40046ef6dc41c98e41a4f8
Processing redis-2.7.6.tar.gz
Running redis-2.7.6/setup.py -q bdist_egg --dist-dir /tmp/easy_install-v8JaAU/redis-2.7.6/egg-dist-tmp-6xgSQs
zip_safe flag not set; 易做图yzing archive contents...
Adding redis 2.7.6 to easy-install.pth file
Installed /usr/local/lib/python2.6/site-packages/redis-2.7.6-py2.6.egg
Processing dependencies for redis
Finished processing dependencies for redis
[root@localhost etc]# easy_install redis
Searc
补充:Web开发 , Python ,