Skip to content

通过知识获得解放,通过技术获得自由

Menu
  • 专题目录
  • 液压相关
    • 液压技术
    • 液压相邻技术
    • 液压应用
  • 计算机相关
    • 计算机和软件
    • 网络和网站技术
  • 哲学
  • 关于本站
Menu

安装redis6.2.4和php7.4的redis插件[0]

Posted on 2023年11月14日 by

本篇参照安装redis和php的redis扩展进行安装

  • 安装redis5.0.3
yum install redis
systemctl enable redis
nano /usr/local/redis/etc/redis.conf

启动redis

systemctl start redis
  • 安装redis6.2.4
cd /lnmp
yum remove redis
wget https://www.fanlog.org/wp-content/uploads/2021/06/redis-6.2.4.zip
unzip redis-6.2.4.zip
tar xzf redis-6.2.4.tar.gz
cd redis-6.2.4
make
make test
make install PREFIX=/usr/local/redis
mkdir -p /usr/local/redis/etc
mv /lnmp/redis-6.2.4/redis.conf /usr/local/redis/etc

修改redis.conf如下:

nano /usr/local/redis/etc/redis.conf
修改如下:
daemonize yes

添加系统服务

nano /usr/lib/systemd/system/redis.service
添加如下
[Unit]
Description=redis
After=network.target
[Service]
Type=forking
ExecStart=/usr/local/redis/bin/redis-server /usr/local/redis/etc/redis.conf
ExecStop=/usr/local/redis/bin/redis-cli shutdown
Restart=always
[Install]
WantedBy=multi-user.target

  • 安装php7.4的redis插件

 

cd /lnmp
wget https://www.fanlog.org/wp-content/uploads/2021/06/phpredis-5.2.0.zip
unzip phpredis-5.2.0.zip
tar xzf phpredis-5.2.0.tar.gz
cd phpredis-5.2.0/
/usr/local/php/bin/phpize
./configure --with-php-config=/usr/local/php/bin/php-config
make
make install

修改php.ini

nano /usr/local/php/lib/php.ini
添加
extension=redis.so

重启php-pfm

systemctl restart php-fpm

 

使用redis1.php进行测试

<?php
    //连接本地的 Redis 服务
   $redis = new Redis();
   $redis->connect('127.0.0.1', 6379);
   echo "Connection to server successfully";
         //查看服务是否运行
   echo "Server is running: " . $redis->ping();
?>

显示结果如下:

Connection to server successfullyServer is running: 1

使用redis2.php进行测试

<?php
   //连接本地的 Redis 服务
   $redis = new Redis();
   $redis->connect('127.0.0.1', 6379);
   echo "Connection to server successfully";
   //设置 redis 字符串数据
   $redis->set("tutorial-name", "Redis tutorial");
   // 获取存储的数据并输出
   echo "Stored string in redis:: " . $redis->get("tutorial-name");
?>

显示结果如下:

Connection to server successfullyStored string in redis:: Redis tutorial

使用redis3.php进行测试

<?php
   //连接本地的 Redis 服务
   $redis = new Redis();
   $redis->connect('127.0.0.1', 6379);
   echo "Connection to server successfully";
   //存储数据到列表中
   $redis->lpush("tutorial-list", "Redis");
   $redis->lpush("tutorial-list", "Mongodb");
   $redis->lpush("tutorial-list", "Mysql");
   // 获取存储的数据并输出
   $arList = $redis->lrange("tutorial-list", 0 ,5);
   echo "Stored string in redis";
   print_r($arList);
?>

显示结果如下:

Connection to server successfullyStored string in redisArray ( [0] => Mysql [1] => Mongodb [2] => Redis [3] => Mysql [4] => Mongodb [5] => Redis )

使用redis4.php进行测试

<?php
   //连接本地的 Redis 服务
   $redis = new Redis();
   $redis->connect('127.0.0.1', 6379);
   echo "Connection to server successfully";
   // 获取数据并输出
   $arList = $redis->keys("*");
   echo "Stored keys in redis:: ";
   print_r($arList);
?>

显示结果如下:

Connection to server successfullyStored keys in redis:: Array ( [0] => PHPREDIS_SESSION:16vggb42sp1ildndl9mts2ro53 [1] => PHPREDIS_SESSION:fuutmo2np1jo6gmmga4jvpc181 [2] => tutorial-list [3] => tutorial-name [4] => PHPREDIS_SESSION:6dg28l765fe2tp9rsmoh6ue5pl [5] => PHPREDIS_SESSION:htk39rjc4v4cs32vau4auba9l4 [6] => PHPREDIS_SESSION:vrg3a8in7btsrl7oml0u1jaif2 [7] => PHPREDIS_SESSION:a9ftc67bc9qqhir62jhsqnmc7d [8] => PHPREDIS_SESSION:fkes93qa36acmll25r5gvg7fje [9] => PHPREDIS_SESSION:6qq60safhi9v8ctv4qufua1aj0 [10] => PHPREDIS_SESSION:gvae9sjliceb9fckus04bljk7m )

 

参考资料:

  1. https://www.daehub.com/archives/9663.html
  2. https://www.runoob.com/redis/redis-php.html

欢迎回来

希望本站对你有所帮助!

如有疑问请联系info@fanlog.org
2023 年 11 月
一二三四五六日
 12345
6789101112
13141516171819
20212223242526
27282930 
« 6 月    

AI辅助 (17)

© 2025 | Powered by Superbs Personal Blog theme
We use cookies on our website to give you the most relevant experience by remembering your preferences and repeat visits. By clicking “Accept All”, you consent to the use of ALL the cookies. However, you may visit "Cookie Settings" to provide a controlled consent.
Cookie SettingsAccept All
Manage consent

Privacy Overview

This website uses cookies to improve your experience while you navigate through the website. Out of these, the cookies that are categorized as necessary are stored on your browser as they are essential for the working of basic functionalities of the website. We also use third-party cookies that help us analyze and understand how you use this website. These cookies will be stored in your browser only with your consent. You also have the option to opt-out of these cookies. But opting out of some of these cookies may affect your browsing experience.
Necessary
Always Enabled
Necessary cookies are absolutely essential for the website to function properly. This category only includes cookies that ensures basic functionalities and security features of the website. These cookies do not store any personal information.
Non-necessary
Any cookies that may not be particularly necessary for the website to function and is used specifically to collect user personal data via analytics, ads, other embedded contents are termed as non-necessary cookies. It is mandatory to procure user consent prior to running these cookies on your website.
SAVE & ACCEPT