源地址:http://mirrors.ustc.edu.cn/fedora/epel/6/x86_64/epel-release-6-8.noarch.rpm //此为centos 6版本
安装输入命令:
步骤一 :
# wget http://mirrors.ustc.edu.cn/fedora/epel/6/x86_64/epel-release-6-8.noarch.rpm # rpm -ivh epel-release-6-8.noarch.rpm # yum install redis php-redis # /etc/init.d/redis start //安装成功启动redis
步骤二 :
# vim /etc/sysconfig/iptables //配置防火墙 # -A INPUT -p tcp -m tcp --dport 6379 -j ACCEPT //在iptables里添加这一行,开放6379端口(6379为redis默认端口) # service iptables restart //重启服务
步骤三 :
# vim /etc/redis.conf //打开redis配置文件 # bind 127.0.0.1 //注释,即加#号---可外网访问 # service redis restart //重启服务
步骤四 :
# cd /usr/lib64/php/modules/ # echo ‘extension=redis.so‘ > /etc/php.d/redis.ini //引入redis.so # vim /etc/php.d/redis.ini //去掉前面单引号(即去掉注释) # service httpd restart //重启Apache
测试:
# redis-cli redis 127.0.0.1:6379> set a "Hello" //赋值 OK redis 127.0.0.1:6379> get a "Hello" //取值
php代码:
<?php $redis = new Redis(); $redis->connect(‘127.0.0.1‘,6379); $redis->set(‘a‘,‘Hello‘); echo $redis->get(‘a‘); ?>
ps:window版
cmd下载地址:https://github.com/dmajkic/redis/downloads
服务安装包:https://github.com/rgl/redis/downloads
时间: 2024-10-29 05:01:21