Redis的安装部署
Posted 韦建国
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Redis的安装部署相关的知识,希望对你有一定的参考价值。
安装php
yum install php php-devel -y
安装php扩展支持memcache
yum -y install php-pecl-memcache
yum -y install php56w-pecl-memcache //如php端是5.6,我们不是5.6,不用装
安装redis
----------------------------------------------------------------------------------------------------
安装redis和php支持模块
rpm -Uvh https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm //下载源
yum clean all
yum install -y redis php-redis //让php支持redis
添加php支持redis模块 在结尾处进行添加
vim /etc/php.ini
-------------------------------------------------
extension=redis.so
-------------------------------------------------
systemctl restart httpd //重启httpd ,php也会随之起来
vim /etc/redis.conf //开启进程,才能启动
---------------------------------------------------------
daemonize yes
---------------------------------------------------------
systemctl restart redis
ps -ef | grep redis
测试:
---------------------------------------------------------------
测试一下客户端是否好用
redis-cli set hx value //存值
redis-cli get hx //取值
添加测试页面
cd /var/www/html/
vim test.php
-----------------------------------------------
<?php
phpinfo();
?>
-----------------------------------------------
vim session.php //统计网页的访问次数
---------------------------------------------------------------------------------
<?php
session_start();
$count = isset($_SESSION[count]) ? $_SESSION[count] : 1;
echo $count;
$_SESSION[count] = ++$count;
?>
--------------------------------------------------------------------------------
vim redis.php
------------------------------------------------------------------------------------------
<?php
$redis = new Redis();
$redis->connect(127.0.0.1, 6379);
$redis->set(key, value);
echo $redis->get(key)."\\n";
$redis->setex(key, 3600, value); // sets key → value, with 1h TTL.
$redis->set(key1, val1);
$redis->set(key2, val2);
$redis->set(key3, val3);
$redis->set(key4, val4);
$redis->delete(key1, key2);
echo $redis->get(key3)."\\n" ;
$redis->delete(array(key3, key4));
?>
新测试页面:
通过key获取value
<?php
$redis = new Redis();
$redis->connect(127.0.0.1, 6379);
$redis->set(jkl, 123);
echo $redis->get(jkl)."\\n";
?>
以上是关于Redis的安装部署的主要内容,如果未能解决你的问题,请参考以下文章