redis连接服务器记录

2022/06/22

正常情况如下

前期准备

用yum install redis

连接准备

1.启动redis
systemctl start redis
2.查看一下redis状态
ps -ef |grep redis

redis连接服务器记录_第1张图片
3.这里连接的是本机服务器
redis连接服务器记录_第2张图片

@Resource
    private RedisTemplate redisTemplate;
    @RequestMapping("/redis")
    public void redis(){

            redisTemplate.opsForValue().set("张三","18");
            System.out.println(redisTemplate.opsForValue().get("张三"));


非正常情况(我遇到的)

第一点
出现连接超时
在这里插入图片描述
配置一下超时时间就可以了
redis连接服务器记录_第3张图片
第二点
连接错误
进入redis配置文件修改配置(pagedown 翻页)
命令: vim /etc/redis.conf
关闭线程守护:
redis连接服务器记录_第4张图片
注释掉 bind 127.0.0.1
redis连接服务器记录_第5张图片
关闭防火命令
systemctl stop firewalld
查看防火墙状态
systemctl status firewalld
active:inactive(dead)就是关闭了
在这里插入图片active出现描述

第三点
NOAUTH Authentication required
同样使用 vim /etc/redis.conf
查看密码在yml类里边配置密码即可(当然是在密码未配置的情况下,也不排除其他情况)

以上配置都设置完成后 仍出现错误

使用主机ping一下 远程服务器的网址
如下则正常
redis连接服务器记录_第6张图片
再试一下:
telnet ip 端口号
例如
telnet 127.0.0.1 6379
如下情况则可正常通信

redis连接服务器记录_第7张图片
若是如下 则失败 尝试配置阿里云内出口外出口是否开启访问的端口
redis连接服务器记录_第8张图片

你可能感兴趣的:(服务器,redis,linux)