Redis 安装与配置
》 Linux安装:
redis的编译简单得不能再简单,不愧是简单好用的产品。
# tar -zxvf redis-2.8.16.tar.gz
# cd redis-2.8.16
# make
# make test
# make PREFIX=/usr/local/redis install
之前centos下有个必须的东西是 tcl, 从库安装即可。
而且,它已经复制到了相应bin之下, 可以直接# redis-server 启动。
控制脚本:
# cp redis-2.8.16/redis.conf /etc/redis/redis.conf
# vim /etc/init.d/redis
#!/bin/sh # chkconfig: 2345 90 10 # description: Redis is a persistent key-value database # redis Startup script for redis processes # processname: redis redis_path="/usr/local/bin/redis-server" redis_conf="/etc/redis/redis.conf" redis_pid="/var/run/redis.pid" # Source function library. . /etc/rc.d/init.d/functions [ -x $redis_path ] || exit 0 RETVAL=0 prog="redis" # Start daemons. start() { if [ -e $redis_pid -a ! -z $redis_pid ];then echo $prog" already running...." exit 1 fi echo -n $"Starting $prog " # Single instance for all caches $redis_path $redis_conf RETVAL=$? [ $RETVAL -eq 0 ] && { touch /var/lock/subsys/$prog success $"$prog" } echo return $RETVAL } # Stop daemons. stop() { echo -n $"Stopping $prog " killproc -d 10 $redis_path echo [ $RETVAL = 0 ] && rm -f $redis_pid /var/lock/subsys/$prog RETVAL=$? return $RETVAL } # See how we were called. case "$1" in start) start ;; stop) stop ;; status) status $prog RETVAL=$? ;; restart) stop start ;; condrestart) if test "x`pidof redis`" != x; then stop start fi ;; *) echo $"Usage: $0 {start|stop|status|restart|condrestart}" exit 1 esac exit $RETVAL
chmod 755 /etc/init.d/redis
将此脚本加入开机启动:
chkconfig --level 2345 redis on
》 Windows安装:
下载windows版redis(github, 此版本目录 bin/release/redis-x.x.x.zip 下为windows版,解压, 改 redis.windows.conf 为 redis.conf)。
运行 redis-server.exe, 默认使用 redis.conf 配置。
》搭配PHP:
安装php_redis 扩展:
通过phpinfo确定 php版本、compiler版本、 是ts还是nts, 下载对应扩展(https://github.com/nicolasff/phpredis/downloads)
解压文件并复制到php/ext,php.ini 添加
extension=php_igbinary.dll
extension=php_redis.dll
加载成功后, php中使用 $redis = new Redis(); 即可初始化。
或者代码使用 predis 包(建议,更方便)。