redis-cli Could not connect to Redis at 127.0.0.1:6379: Connection refused

1. 启动 Redis 服务

在 macOS 上:

bash 复制代码
# 如果使用 Homebrew 安装的 Redis
brew services start redis

# 或者手动启动
redis-server /usr/local/etc/redis.conf

在 Linux 上:

bash 复制代码
# Ubuntu/Debian
sudo systemctl start redis-server
sudo systemctl enable redis-server

# CentOS/RHEL
sudo systemctl start redis
sudo systemctl enable redis

在 Windows 上:

bash 复制代码
# 如果作为服务安装
redis-server --service-start

2. 检查 Redis 服务状态

macOS (Homebrew):

bash 复制代码
brew services list

Linux:

bash 复制代码
sudo systemctl status redis-server
# 或
sudo systemctl status redis

3. 检查 Redis 配置

查看 Redis 是否在非默认端口运行:

bash 复制代码
ps aux | grep redis

如果 Redis 在其他端口运行,连接时指定端口:

bash 复制代码
redis-cli -p 6380  # 替换为实际端口

4. 安装 Redis(如果尚未安装)

macOS:

bash 复制代码
brew install redis

Ubuntu/Debian:

bash 复制代码
sudo apt update
sudo apt install redis-server

CentOS/RHEL:

bash 复制代码
sudo yum install redis
# 或
sudo dnf install redis

5. 测试连接

服务启动后,测试连接:

bash 复制代码
redis-cli ping

应该返回 PONG

6. 检查防火墙设置

确保防火墙没有阻止 Redis 端口:

bash 复制代码
# 检查防火墙状态
sudo ufw status  # Ubuntu
sudo firewall-cmd --list-all  # CentOS

7. 查看 Redis 日志

如果启动失败,查看日志:

bash 复制代码
# macOS
tail -f /usr/local/var/log/redis.log

# Linux
sudo tail -f /var/log/redis/redis-server.log

选择适合你系统的方法,通常启动 Redis 服务后问题就能解决。

相关推荐
她说..2 小时前
策略模式+工厂模式实现审批流(面试问答版)
java·后端·spring·面试·springboot·策略模式·javaee
梦梦代码精3 小时前
开源、免费、可商用:BuildingAI一站式体验报告
开发语言·前端·数据结构·人工智能·后端·开源·知识图谱
李慕婉学姐4 小时前
【开题答辩过程】以《基于Spring Boot的疗养院理疗管理系统的设计与实现》为例,不知道这个选题怎么做的,不知道这个选题怎么开题答辩的可以进来看看
java·spring boot·后端
tb_first4 小时前
SSM速通2
java·javascript·后端
一路向北⁢4 小时前
Spring Boot 3 整合 SSE (Server-Sent Events) 企业级最佳实践(一)
java·spring boot·后端·sse·通信
风象南4 小时前
JFR:Spring Boot 应用的性能诊断利器
java·spring boot·后端
爱吃山竹的大肚肚4 小时前
微服务间通过Feign传输文件,处理MultipartFile类型
java·spring boot·后端·spring cloud·微服务
毕设源码-邱学长6 小时前
【开题答辩全过程】以 基于Springboot的酒店住宿信息管理系统的设计与实现为例,包含答辩的问题和答案
java·spring boot·后端
咖啡啡不加糖7 小时前
Grafana 监控服务指标使用指南:打造可视化监控体系
java·后端·grafana
gAlAxy...7 小时前
SpringBoot Servlet 容器全解析:嵌入式配置与外置容器部署
spring boot·后端·servlet