Jedis 连接 Redis 常见错误

Redis学习(四):Redis的JavaAPI操作 学习目标第一步:创建maven工程并导入jar包第二步:连接以及关闭redis客户端第三步:redis的javaAPI操作操作string类型数据操作hash列表类型数据操作list类型数据操作set类型的数据练习题使用List实现以下功能(javaAPI)使用Set实现以下功能(javaAPI) redis不仅可以通过命令行进行操作,同时redis也可以通过javaAPI进行操作,我们可以通过使... 阅读详情

 

1、SocketTimeoutException 连接超时

redis.clients.jedis.exceptions.JedisConnectionException: java.net.SocketTimeoutException: connect timed out

    at redis.clients.jedis.Connection.connect(Connection.java:154)

    at redis.clients.jedis.BinaryClient.connect(BinaryClient.java:83)

    at redis.clients.jedis.Connection.sendCommand(Connection.java:93)

    at redis.clients.jedis.Connection.sendCommand(Connection.java:88)

    at redis.clients.jedis.Jedis.get(Jedis.java:97)

    at com.zyao89.jedis.JedisTest.test1(JedisTest.java:18)

    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)

    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)

    at java.lang.reflect.Method.invoke(Unknown Source)

    at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)

    at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)

    at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)

    at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)

    at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)

    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)

    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)

    at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)

    at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)

    at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)

    at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)

    at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)

    at org.junit.runners.ParentRunner.run(ParentRunner.java:363)

    at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:86)

    at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)

    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:459)

    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:678)

    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:382)

    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:192)

Caused by: java.net.SocketTimeoutException: connect timed out

    at java.net.DualStackPlainSocketImpl.waitForConnect(Native Method)

    at java.net.DualStackPlainSocketImpl.socketConnect(Unknown Source)

    at java.net.AbstractPlainSocketImpl.doConnect(Unknown Source)

    at java.net.AbstractPlainSocketImpl.connectToAddress(Unknown Source)

    at java.net.AbstractPlainSocketImpl.connect(Unknown Source)

    at java.net.PlainSocketImpl.connect(Unknown Source)

    at java.net.SocksSocketImpl.connect(Unknown Source)

    at java.net.Socket.connect(Unknown Source)

    at redis.clients.jedis.Connection.connect(Connection.java:148)

    ... 28 more

 

这种情况先排除是否开启了redis,或者ip,端口是否正确。如果都没问题,那八成就是防火墙了。

 

可能是redis的6379端口无法访问,请先在cmd中输入命令

 

telnet 127.0.0.1 6379

 

如果不能访问,需要在远程机器关掉防火墙或者添加允许通过

CentOS,root用户登陆,输入如下命令开启端口:

/sbin/iptables -I INPUT -p tcp --dport 6379 -j ACCEPT

刷新自动启动保存

/etc/rc.d/init.d/iptables save

2、Connection refused 拒绝访问

Exception in thread "main" redis.clients.jedis.exceptions.JedisConnectionException: java.net.ConnectException: Connection refused: connect

    at redis.clients.jedis.Connection.connect(Connection.java:207)

    at redis.clients.jedis.BinaryClient.connect(BinaryClient.java:93)

    at redis.clients.jedis.Connection.sendCommand(Connection.java:126)

    at redis.clients.jedis.Connection.sendCommand(Connection.java:121)

    at redis.clients.jedis.BinaryClient.ping(BinaryClient.java:106)

    at redis.clients.jedis.BinaryJedis.ping(BinaryJedis.java:195)

    at practice.RedisJava.main(RedisJava.java:13)

Caused by: java.net.ConnectException: Connection refused: connect

    at java.net.DualStackPlainSocketImpl.waitForConnect(Native Method)

    at java.net.DualStackPlainSocketImpl.socketConnect(DualStackPlainSocketImpl.java:85)

    at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:350)

    at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:206)

    at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:188)

    at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:172)

    at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)

    at java.net.Socket.connect(Socket.java:589)

    at redis.clients.jedis.Connection.connect(Connection.java:184)

    ... 6 more

修改redis.conf配置文件,使用vim命令打开,找到bind那行修改后,wq保存退出,重启redis-server。

redis.conf编辑后

编辑后如上图,用#号注释。

3、DENIED Redis is running in protected mode (保护模式)

redis.clients.jedis.exceptions.JedisDataException: DENIED Redis is running in protected mode because protected mode is enabled, no bind address was specified, no authentication password is requested to clients. In this mode connections are only accepted from the loopback interface. If you want to connect from external computers to Redis you may adopt one of the following solutions: 1) Just disable protected mode sending the command 'CONFIG SET protected-mode no' from the loopback interface by connecting to Redis from the same host the server is running, however MAKE SURE Redis is not publicly accessible from internet if you do so. Use CONFIG REWRITE to make this change permanent. 2) Alternatively you can just disable the protected mode by editing the Redis configuration file, and setting the protected mode option to 'no', and then restarting the server. 3) If you started the server manually just for testing, restart it with the '--protected-mode no' option. 4) Setup a bind address or an authentication password. NOTE: You only need to do one of the above things in order for the server to start accepting connections from the outside.

    at redis.clients.jedis.Protocol.processError(Protocol.java:117)

    at redis.clients.jedis.Protocol.process(Protocol.java:142)

    at redis.clients.jedis.Protocol.read(Protocol.java:196)

    at redis.clients.jedis.Connection.readProtocolWithCheckingBroken(Connection.java:288)

    at redis.clients.jedis.Connection.getBinaryBulkReply(Connection.java:207)

    at redis.clients.jedis.Connection.getBulkReply(Connection.java:196)

    at redis.clients.jedis.Jedis.get(Jedis.java:98)

    at com.zyao89.jedis.JedisTest.test1(JedisTest.java:18)

    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)

    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)

    at java.lang.reflect.Method.invoke(Unknown Source)

    at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)

    at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)

    at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)

    at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)

    at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)

    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)

    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)

    at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)

    at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)

    at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)

    at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)

    at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)

    at org.junit.runners.ParentRunner.run(ParentRunner.java:363)

    at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:86)

    at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)

    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:459)

    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:678)

    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:382)

    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:192)

报错信息很长,但是主要是说redis开启了protected mode,这也是Redis3.2加入的新特性,开启保护模式的redis只允许本机登录,同样设置在配置文件redis.conf中,如图

redis.conf编辑后

这里原来是yes代表开启了保护模式,后面可以填密码也可以填no代表关闭,我们这里选择关闭保护模式,wq保存退出后再重启redis-server。

详细解决redis.clients.jedis.exceptions.JedisConnectionException: Could not get a resource from the pool redis.clients.jedis.exceptions.JedisConnectionException: Could not get a resource from the pool的多种详细的解决方法 阅读详情

相关推荐

正确解决JedisConnectionException: Could not get a resource from the pool异常的有效解决方法

正确解决redis.clients.jedis.exceptions.JedisConnectionException: Could not get a resource from the pool异常的有效解决方法

wbajsjhhhhh的博客 7603

redis.clients.jedis.exceptions.JedisConnectionException: java.net.SocketTimeoutException: connect ti

  redis连接报错: redis.clients.jedis.exceptions.JedisConnectionException: java.net.SocketTimeoutException: connect timed out 开启防火墙(systemctl start firewalld) 1.使用命令  firewall-cmd --state查看防火墙状态。得到结果是r...

云下的你 1万+

微生物测序分析LEfSe

LEfse分析定义 LEfse分析即LDA Effect Size分析,可以实现多个分组之间的比较,还进行分组比较的内部进行亚组比较分析,从而找到组间在丰度上有显著差异的物种(即biomaker);

宁生信 5万+

redis-错误:redis.clients.jedis.exceptions.JedisConnectionException: java.net.SocketTimeoutException: R

redis-错误:redis.clients.jedis.exceptions.JedisConnectionException: java.net.SocketTimeoutException: Read timed out 问题:redis是基于内存的,所以一般来说反应速度是毫秒级的,但是在本机开发测试的时候遇到大的数量及访问或者是高频的访问会造成socket的延时增加到秒级,由redis.c...

weixin_38061311的博客 2496

Windows 11 24H2 系统下,保姆级安装华为 eNSP 模拟器(含依赖软件下载与避坑指南)

本文提供Windows 11 24H2系统下华为eNSP模拟器的完整安装指南,涵盖系统配置调整、依赖软件安装及常见问题解决方案。特别针对新版系统的兼容性问题,提供详细的避坑步骤和优化建议,帮助网络工程师顺利完成eNSP模拟器的部署与使用。

weixin_42567752的博客 431

Winget安装失败:深入解析InternetOpenUrl()错误0x80072efd的根源与修复

本文深入解析了使用Winget时遇到的InternetOpenUrl()错误0x80072efd。该错误通常源于DNS解析失败、网络代理配置不当或系统安全策略冲突,导致无法连接软件源。文章提供了从刷新DNS、修改Hosts文件到配置代理等一套完整的诊断与修复方案,帮助开发者快速解决安装障碍,恢复Winget的正常使用。

weixin_29290259的博客 937

jedis客户端连接redis错误总结

Exception in thread "main" redis.clients.jedis.exceptions.JedisConnectionException: java.net.ConnectException: Connection refused: connect     at redis.clients.jedis.Connection.connect(Connection.jav...

qq_40368860的博客 2412

全网最详细 解决戴维南定理的详细推导

替代定理,戴维南定理详细证明

m0_52555753的博客 3万+

测试Jedis连接Redis出现错误

使用Jedis连接的jar包:     jedis-2.7.3.jar     commons-pool2-2.4.jar 贴出测试代码: 测试连接时,报错误如下: package com.xu.jedis; import org.junit.Test; import redis.clients.jedis.Jedis; /** * jedis测试 * @author San...

Sanders_xu的博客 554

ExpressLRS(ELRS)接收机技术全景:从历史演进、技术底层到产业生态全解析——上

ExpressLRS(ELRS)是一种由全球开源社区驱动的双向射频遥控链路协议栈,其接收机作为核心终端,承担信号接收解调、遥控指令解析、飞控数据交互与遥测回传等关键功能。自2018年问世以来,ELRS凭借极致性能、低成本、开放生态和强兼容性,从航模DIY方案发展为消费级无人机领域的事实标准,并逐步渗透工业级场景。 ELRS接收机采用模块化分层架构,支持2.4GHz和900MHz双频段,通过LoRa、FLRC、FSK多调制模式实现低延迟与远距离平衡。其核心技术包括自适应跳频抗干扰、TDD双向链路和极简数据包。

bother3000的博客 305

逆强化学习:从专家示范中学习策略

逆强化学习(Inverse Reinforcement Learning,简称IRL)是强化学习(Reinforcement Learning,简称RL)的一个子领域,它的目标是从专家的行为中学习策略。在传统的强化学习中,智能体通过与环境交互,根据奖励信号来学习一个策略。而在逆强化学习中,我们没有直接的奖励信号,而是通过观察专家的行为来推断出奖励函数,从而学习到一个与专家类似的策略。逆强化学习作为强化学习的一个重要子领域,在许多实际应用场景中都取得了显著的成功。

AI天才研究院 1456

Jedis远程连接redis-server出现错误解决方法

今天用jedis远程连接redis的时候报错: redis.clients.jedis.exceptions.JedisConnectionException: Failed connecting to host xxx.xxx.xxx.xxx:6379 连接失败,网上查到和配置文件里的某个配置有关系,所以打算去官网查看一下配置文件的官方文档 Redis is able to start without a configuration file using a built-in default con

你的深度学习小站 1777

基于摩尔线程 S80 显卡在 Ubuntu 系统下双卡交火部署 DeepSeek

curl -X POST -H "Content-Type: application/json" -d '{"prompt": "你的问题"}' http://localhost:11434/api/generate。curl -X POST -H "Content-Type: application/json" -d '{"prompt": "你的问题"}' http://localhost:11434/api/generate。- 为避免模型占用系统盘空间,可将模型存储路径修改到其他磁盘。

靡不有初,鲜克有终 1202

linux本地redis连接错误,用jedis连接linux系统的redis时出现连接超时的错误

出现的错误:redis.clients.jedis.exceptions.JedisConnectionException: java.net.SocketTimeoutException: connect timed outat redis.clients.jedis.Connection.connect(Connection.java:154)at redis.clients.jedis.Bi...

weixin_42339991的博客 393

全志T527-TP9930-Camera

TP9930 驱动模块主要实现将 4 路的 AHD/TVI/CVBS Camera 的数据转换为 BT656/BT1120 数据,从而实现在 T527 端来对数据进行处理和送显。

Linux驱动开发工程师,熟悉Linux/Android底层驱动、TP、显示、IIC、网络等通用外设调试适配,Linux上层应用开发。常用平台瑞芯微、全志、恩智浦等。 3247

Statistics and Machine Learning Toolbox

Statistics and Machine Learning Toolbox(带书签),MATLAB统计学习工具

使用jedis连接redis的常见错误

1 提示connection refused 原因:host,port填错了/redis-server没启动 2 提示connection denied redis.clients.jedis.exceptions.JedisDataException: DENIED Redis is running in protected mode because protected mode is ...

weixin_43860716的博客 421

大中型超市收银系统(可直接运行)

光步前台收银系统系统功能:商品销售、商品退货、挂单、收银员权限、会员销售、单品取消、整单取消、商品查询、脱机销售、脱机数据上传,基本资料下载,开钱箱、小票打印、收款结算,支持多币种付款方式(现金、储值卡、礼券、微信等),支持多种促销。运行环境:.net 4.0登陆信息用户名:1001 密码:123456内置商品信息,商品编码可输入00001000 - 00010000,测试效果相关功能键F5 结算 F9挂单 F11商品查询 F8退货 Insert单品取消 Del整单取消 F12开钱箱F2 会员 Ctrl+Z退出系统 Home 锁屏 相关源码待公开

使用Jedis 连接 Redis 时可能出现的常见错误

本人作为一个初学者学习Redis的使用,遇到了下面一些异常,总结了一些解决方案。1、SocketTimeoutException 连接超时redis.clients.jedis.exceptions.JedisConnectionException: java.net.SocketTimeoutException: connect timed out这种情况先排除是否开启了redis,或者ip地址...

asa_liuchen的博客 1万+

android 蓝牙通讯demo

android 下蓝牙通讯demo,实现了发现蓝牙,使能蓝牙,通过蓝牙发送消息。

锂电池充电器电路设计 里面有电路

锂电池充电器电路设计 里面有电路 3.7V升压到5V电路设计。

Jedis操作Redis连接错误解决

 连接Redis时出现以下错误 redis.clients.jedis.exceptions.JedisConnectionException: java.net.SocketTimeoutException: connect timed out 检查了虚拟机的ip和Redis的端口,均无错误  1、防火墙放行6379端口 2、更改配置文件,注释掉:bind 127.0.0.1 3、关...

皮一下很开心的猴头 592

Java通过Jedis连接Redis异常,错误记录

紧接上一篇文章,Centos7下Redis安装教程 我用Jedis连接Redis时报错,代码和错误如下图 解决方案: 在redis.conf这个配置文件中,找到bind和protected-mode这两个属性,将其修改。 默认: 修改后: 在vmware中创建centos7虚拟机并安装Redis后,如果以redis.conf配置文件运行的话,只能本机(仅仅是...

wangzhen的博客 641

Jedis连接不上redis服务器常见错误

错误一:bind配置参数绑定了127.0.0.1 安装好redis服务器,使用Jedis操作redis Jedis jedis = new Jedis("xxx.xxx.xxx.xxx",6379); jedis.set("key","value"); 报了以下异常: Exception in thread "main" redis.clients.jedis.exceptions.J...

LINBE_blazers的博客 1361

连接redis出现错误:Cannot get Jedis connection

错误信息: 错误描述:由于我的redis数据库没有设置密码,配置连接的时候我配置了密码为空,导致连接失败 转载于:https://www.cnblogs.com/wangxiayun/p/9330138.html...

dd10850的博客 2041

jedis连接docker中redis容器报密码相关错误 解决方案

文章说明 注意: 此文章为docker从0搭建redis直观的解决jedis连接redis密码报错问题. 如可以接受每次重启服务器手动设置redis密码,可不参考文章所有内容。 此文为个人的方案,如未帮到你或找到了更好的方法,勿喷. docker创建redis容器一定要设置密码,不然每次重启服都要设置密码很繁琐。 2020.7.4日时 在跟着案例写一个模块时,测试一个发送消息的功能,连接redis报错。具体解决问题也是折腾了近三个小时参考资料才得以解决,有说是连接池太小,还是不得了之。最终解决的方法 再次设

情話微甜 的博客 1047

Redis-jedis连接池配置错误导致Redis CPU飙高

今天业务突然告知 Redis 访问比较慢,但 Redis 侧并没有什么告警,经过一系列排查,最终发现 auth 认证的频率过高,定位到业务测连接池配置有问题,最终解决问题。

line_on_database的博客 70
上一篇: hostname和/etc/hosts的区别
下一篇: MongoDB基本命令用法
MatrixGod
博客等级 码龄11年 29粉丝 10原创
评论 1
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值