Linux_redis/phpredis
1、安装redis
安装
tar -zxvf redis-2.6.17.tar.gz
cp redis-2.6.17 /usr/local/redis
cd /usr/local/redis/
make && make install
vim redis.conf
修改配置
daemonize yes #以守护进程方式运行
dir /usr/local/redis #使redis-server可在任意目录下执行
appendonly yes #指定是否在每次更新操作后进行日志记录
开机自启动
服务脚本:
vim /etc/init.d/redis
脚本内容:
# chkconfig: 2345 10 90
# description: Start and Stop redis
PATH=/usr/local/bin:/sbin:/usr/bin:/bin
REDISPORT=6379
EXEC=/usr/local/bin/redis-server
REDIS_CLI=/usr/local/bin/redis-cli
PIDFILE=/var/run/redis.pid
CONF="/usr/local/redis/redis.conf"
AUTH="1234"
case "$1" in
start)
if [ -f $PIDFILE ]
then
echo "$PIDFILE exists, process is already running or crashed."
else
echo "Starting Redis server..."
$EXEC $CONF
fi
if [ "$?"="0" ]
then
echo "Redis is running..."
fi
;;
stop)
if [ ! -f $PIDFILE ]
then
echo "$PIDFILE exists, process is not running."
else
PID=$(cat $PIDFILE)
echo "Stopping..."
$REDIS_CLI -p $REDISPORT SHUTDOWN
sleep 2
while [ -x $PIDFILE ]
do
echo "Waiting for Redis to shutdown..."
sleep 1
done
echo "Redis stopped"
fi
;;
restart|force-reload)
${0} stop
${0} start
;;
*)
echo "Usage: /etc/init.d/redis {start|stop|restart|force-reload}" >&2
exit 1
esac
设置开机自启动
chkconfig redis on
重启
reboot
连接
redis-cli
2、安装phpredis
下载
http://pecl.php.net/package/redis
安装
tar zxvf redis-3.0.0.tgz
cd redis-3.0.0
/usr/local/php/bin/phpize
./configure --with-php-config=/usr/local/php/bin/php-config
make
make install
php添加redis扩展
find / -name php.ini
vim /usr/local/php/etc/php.ini
添加如下内容:
extension=redis.so
重启服务
service nginx restart
killall php-fpm
service php-fpm start
浏览器访问phpinfo.php即可看到有redis扩展了
new redis();
新建redis.php
$redis = new Redis();
var_dump($redis);
exit;