拾光记录
218个文档 导航 作者 Gitee
随笔记录4
Hexo博客:基础使用Hexo博客:Next主题Hexo博客:Next进阶使用Hexo博客:Next高级配置
前端知识4
基础知识17
Vue框架19
UniApp14
微信小程序1
Java编程6
Java基础15
SpringBoot31
SpringMVC18
MyBatis9
SpringCloud15
中间件2
数据库4
MySQL13
Redis8
MongoDB10
其他数据库1
Python编程6
Python基础知识Python语法yolo目标检测OpenCV的使用及树莓派平台condauv管理工具
Linux12
Linux常用命令Jar启动脚本VirtualBox安装CentOSVirtualBox安装Ubuntu树莓派安装及使用frp内网穿透ArchLinux:基础系统安装ArchLInux:图形化界面安装ArchLinux:常用软件ArchLinux:深度优化ArchLinux:NiriArchLinux:模块记录
软件工具12
IDEAGitMavenGradleNginx安装Nginx配置JMeter压测OllamaRustFSPicGoVSCodeDocker
创意设计2
Blender:入门知识UI设计基础知识
AI相关9
Claude CodeHermes AgentOpenAI基本使用OpenAI工具调用OpenAI记忆管理OpenAI推理执行OpenAI开发框架Langchainllama.cpp

Redis特点和优势

Redis作用

Redis安装

官方网站下载tar压缩包,上传到服务器进行解压

推荐下载源码包:https://download.redis.io/releases/redis-7.4.0.tar.gz,然后自行编译,适用于所有平台

tar -zxvf redis.xxx
# 需要gcc编译
# yum install gcc
# yum install make
make install

然后复制解压目录下的redis.conf/usr/local/bin/redis.xx/(安装目录下,不同系统可能有差别),然后编辑

开启后台运行

默认端口

用配置文件启动Redis

redis-server ./redis.conf

查看端口是否正常启动

netstat -ntulp | grep 6379

连接测试

redis-cli -h localhost -p 6379

配置

开启远程连接,注释掉以下代码

密码配置

连接后使用auth password验证身份

连接工具

https://github.com/qishibo/AnotherRedisDesktopManager/releases

Redis为何快

Redis将所有的数据都放在内存中,使用单线程去操作,多线程有上下文切换(耗时)

开机自启

centos

startRedis.sh
/usr/local/bin/redis-server /usr/local/bin/redis.conf

vim /etc/rc.d/rc.local
/usr/local/bin/startRedis.sh

chmod +x /usr/local/bin/startRedis.sh

启动报错

[root@10 ~]# /usr/local/bin/redis-server /usr/local/bin/redis.conf
2623:C 28 Sep 2024 13:27:43.484 # WARNING Memory overcommit must be enabled! Without it, a background save or replication may fail under low memory condition. Being disabled, it can also cause failures without low memory condition, see https://github.com/jemalloc/jemalloc/issues/1328. To fix this issue add 'vm.overcommit_memory = 1' to /etc/sysctl.conf and then reboot or run the command 'sysctl vm.overcommit_memory=1' for this to take effect.
[root@10 ~]#
echo "1" > /proc/sys/vm/overcommit_memory

出现启动没有响应问题,设置日志文件后,发现提示报错

# Failed to configure LOCALE for invalid locale name.

出现这个问题是由于系统没有正确设置locale环境, 而locale是用于设置本地环境的比如:语言、时区、数字等

解决方案:设置系统环境变量

echo "export LC_ALL=en_US.UTF-8"  >>  /etc/profile
source /etc/profile

windows安装

https://github.com/tporadowski/redis/releases:同理配置后启动

redis-server.exe redis.windows.conf

ubuntu安装

# 官网下载或上传包
wget http://download.redis.io/releases/redis-7.4.0.tar.gz
tar -zxvf redis-7.4.0.tar.gz
sudo apt install build-essential tcl
sudo make install
redis-server --version
配置文件然后启动,不需要放到其他地方
redis-server redis.conf

远程访问需要设置密码才行,记得开防火墙

# 查看已开放端口
firewall-cmd --list-all
# 开放端口
firewall-cmd --zone=public --add-port=6379/tcp --permanent
# 重启生效
firewall-cmd --reload

查看

netstat -ntulp | grep 6379

ubuntu开机执行脚本

创建service文件vim /etc/systemd/system/redisStart.service,加上脚本位置

[Unit]
Description=Run a script on startup

[Service]
ExecStart=/usr/redis-7.4.0/startRedis.sh # 脚本位置
Type=oneshot
RemainAfterExit=yes

[Install]
WantedBy=multi-user.target

创建启动脚本

#!/bin/bash
redis-server /usr/redis-7.4.0/redis.conf

执行

# 加可执行
chmod +x startRedis.sh
# 状态
systemctl status redisStart.service
# 开启
systemctl enable redisStart.service
# 执行
systemctl restart redisStart.service
# 重启
systemctl restart redisStart.service
# 重新加载配置
systemctl daemon-reload

连接超时设置

redis-cli
auth password
config set timeout 0              # Redis服务端不主动断开客户端的空闲连接,0 表示永不超时
config set tcp-keepalive 60       # Redis服务端每隔60秒,向客户端发送一个心跳包,检测连接是否还活着

验证是否生效
config get timeout
config get tcp-keepalive

默认是5分钟

Redis特点和优势Redis作用Redis安装配置连接工具Redis为何快开机自启启动报错windows安装ubuntu安装ubuntu开机执行脚本连接超时设置