一、redis安裝
1)下載redis最新穩定版:http://redis.googlecode.com/files/redis-2.4.14.tar.gz
2)解壓安裝:make & make test
3)可能需要安裝tcl8.5:
3.1)下載tcl8.5源碼包:wget http://downloads.sourceforge.net/tcl/tcl8.5.10-src.tar.gz
3.2)解壓 安裝 :cd unix/ & ./configure --prefix=/usr --enable-threads --mandir=/usr/share/man
3.3)make & sed -i -e "s@^\(TCL_SRC_DIR='\).*@\1/usr/include'@" -e "/TCL_B/s@='\(-L\)\?.*unix@='\1/usr/lib@" tclConfig.sh
3.4)make test & make install && make install-private-headers && ln -v -sf tclsh8.5 /usr/bin/tclsh && chmod -v 755 /usr/lib/libtcl8.5.so
4)安裝:make install
5)修改設定檔:vi /etc/redis.conf
daemonize yes #是否後台進程(yes/no)pidfile /usr/local/redis/var/redis.pid #pid檔案路徑port 6379 #redis server監聽連接埠bind 127.0.0.1 #設定redis綁定的 interface,如果不設定,則搬到所有timeout 300 #用戶端連線逾時時間loglevel debug #日誌等級(debug/verbose/notice/warning)logfile /usr/local/redis/var/redis.log #記錄檔路徑(stdout/file路徑)databases 16 #資料庫的數量,預設資料庫為 DB 0save 90 100000 #資料庫儲存到磁碟的方式:save <seconds> <changes> rdbcompression yes #是否對資料庫資料進行壓縮dbfilename dump.rdb #資料庫資料檔案名稱dir /usr/local/redis/var/ #資料庫資料目錄appendonly no #是否開啟每個操作記錄一條日誌功能appendfsync always #(no 等到系統同步 always 每條記錄同步一次 everysec 每秒同步一次)glueoutputbuf yes #shareobjects noshareobjectspoolsize 1024
6)啟動redis server :/usr/local/bin/redis-server /etc/redis.conf
二、安裝redis-py (redis-py不支援python 2.4)
在修改了部分redis-py的源碼後,終於安裝成功,測試結果如下:
[root@test redis-2.4.13]# pythonPython 2.4.3 (#1, Feb 22 2012, 16:05:45) [GCC 4.1.2 20080704 (Red Hat 4.1.2-52)] on linux2Type "help", "copyright", "credits" or "license" for more information.>>> import redis>>> r = redis.StrictRedis(host='127.0.0.1', port=6379)>>> r.set('foo', 'hello') True>>> r.rpush('mylist', 'one')1L>>> print r.get('foo') hello>>> print r.rpop('mylist')one>>>