一、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 0
- save 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 no
- shareobjectspoolsize 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]# python
- Python 2.4.3 (#1, Feb 22 2012, 16:05:45)
- [GCC 4.1.2 20080704 (Red Hat 4.1.2-52)] on linux2
- Type "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
- >>>