1、安装
安装
sudo apt install redis-server
查看服务状态
sudo systemctl status redis-server
查看文件位置
sudo whereis redis-server
查看版本号
sudo redis-server --version
日志
/var/log/redis/redis-server.log
1.1、源码安装
预先安装make、gcc
sudo apt install make gcc
wget http://download.redis.io/releases/redis-5.0.5.tar.gz
cd src
make MALLOC=libc
make test
sudo make install
如果需要使用make test(可能需要安装tcl8.5或更高版本)
You need tcl 8.5 or newer in order to run the Redis test
http://www.tcl.tk/doc/howto/compile.html#unix
https://sourceforge.net/projects/tcl/files/Tcl/
2、配置
配置文件位置
/etc/redis/redis.conf
3、测试
连接
redis-cli -h 192.168.1.251 -p 6379
查看服务状态信息
192.168.1.251:6379> ping
PONG
192.168.1.251:6379>help ping 查看帮助
退出
192.168.1.251:6379>quit
4、thinkphp连接
1)安装php redis扩展
https://pecl.php.net/package/redis/
https://github.com/phpredis/phpredis/
wget https://pecl.php.net/get/redis-5.0.2.tgz
$ phpize
$ ./configure
$ make
$ make test
$ sudo make install (redis.so自动安装到 /usr/lib/php/20170718 )
sudo chmod -x /usr/lib/php/20170718/redis.so (去掉执行权限)
编辑/etc/php/7.2/fpm/php.ini
extension=redis
重启php-fpm服务
sudo systemctl restart php7.2-fpm
phpinfo中查找 redis
E:svn esttpapiappsconfig.php 配置
'cache' => [
// 驱动方式
'type' => 'redis',
// 缓存保存目录
'path' => CACHE_PATH,
// 缓存前缀
'prefix' => '',
// 缓存有效期 0表示永久缓存
'expire' => 0,
'host'=>'192.168.1.251',
//'port'=>6379,
],
读取、写入、删除、清空参考:
https://www.kancloud.cn/manual/thinkphp5/118131