一、问题

最近弄Reids碰到这个问题

Exception in thread "main" redis.clients.jedis.exceptions.JedisConnectionException: Failed to create socket.at redis.clients.jedis.DefaultJedisSocketFactory.createSocket(DefaultJedisSocketFactory.java:93)at redis.clients.jedis.Connection.connect(Connection.java:180)at redis.clients.jedis.Connection.sendCommand(Connection.java:152)at redis.clients.jedis.Connection.sendCommand(Connection.java:135)at redis.clients.jedis.Jedis.ping(Jedis.java:353)at com.azure.TestRedis.main(TestRedis.java:9)
Caused by: java.net.SocketTimeoutException: connect timed outat java.net.DualStackPlainSocketImpl.waitForConnect(Native Method)at java.net.DualStackPlainSocketImpl.socketConnect(DualStackPlainSocketImpl.java:81)at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:476)at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:218)at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:200)at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:162)at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:394)at java.net.Socket.connect(Socket.java:606)at redis.clients.jedis.DefaultJedisSocketFactory.createSocket(DefaultJedisSocketFactory.java:65)... 5 more

Exception in thread “main” redis.clients.jedis.exceptions.JedisConnectionException: Failed to create socket.

百度翻译
原因是Redis连接超时,因为我是连的阿里的服务器,所以要修改配置文件。

二、解决办法

找到你的Redis安装目录,vim修改这个文件,我的方法是再复制一个配置文件,启动时用新的配置文件启动。

[root@wangazure redis]# cp redis.conf azure.conf  #将redis.conf复制到一个名字为azure.conf里
[root@wangazure redis]# ls
00-RELEASENOTES  CONDUCT       deps      Makefile   redis.conf  runtest-cluster    sentinel.conf  tests   version_check.pl
azure.conf       CONTRIBUTING  dump.rdb  MANIFESTO  redis.log   runtest-moduleapi  src            TLS.md  version.pl
BUGS             COPYING       INSTALL   README.md  runtest     runtest-sentinel   start.pl       utils


修改新的配置文件azure.conf

[root@wangazure redis]# vim azure.conf

注意:进入vim编辑模式要按 i 键才能编辑,推出编辑模式按ESC键,再按分号wq保存
这里有了insert才是编辑模式,

关闭:protected-mode(保护模式)把yes改成no

退出保存(:wq)

这里保存完了要重启下Redis服务。

[root@wangazure redis]# redis-cli -p 6379 shutdown                  #关闭redis
[root@wangazure redis]# pwd                                        #查看文件路径
/www/server/redis[root@wangazure src]# redis-server /www/server/redis/azure.conf   #用新的配置文件重启redis[root@wangazure src]# ps -aux|grep redis                            #查看redis服务
root     15335  0.0  0.1 162588  2640 ?        Ssl  16:23   0:00 redis-server *:6379
root     15364  0.0  0.0 112812   980 pts/0    R+   16:23   0:00 grep --color=auto redis

这里再测试下就好了

三、有一部分人用redis-server会报以下的错

[root@wangazure redis]# redis-server /www/server/redis/azure.conf
-bash: redis-server: command not found

原因:redis-server不是全局命令,那么加入到全局就可以了。

这里要把redis目录src下的redis-server文件复制到/usr/bin下

[root@wangazure src]# pwd #查看路径
/www/server/redis/src
[root@wangazure src]# cp redis-server /usr/bin/redis-server #把当前文件中的redis-server文件复制到/usr/bin下

再次重启Redis,测试下就好了

[root@wangazure src]# redis-cli -p 6379 shutdown                    #关闭redis
[root@wangazure src]# redis-server /www/server/redis/azure.conf    #用新的配置文件重启redis
[root@wangazure src]# ps -aux|grep redis                           #查看redis服务
root     15335  0.0  0.1 162588  2640 ?        Ssl  16:23   0:00 redis-server *:6379
root     15364  0.0  0.0 112812   980 pts/0    R+   16:23   0:00 grep --color=auto redis

四、Redis后台运行

[root@wangazure redis]# vim redis.conf  #进入编辑模式
[root@wangazure redis]#

把daemonize 设置为:yes
当我们采用yes时,Redis会在后台运行,此时Redis将一直运行

daemonize yes

Exception in thread “main“ redis.clients.jedis.exceptions.JedisConnectionException: Failed to create相关推荐

  1. 【已解决】Exception in thread “Thread-0“ redis.clients.jedis.exceptions.JedisConnectionException: java.n

    问题: Exception in thread "Thread-0" redis.clients.jedis.exceptions.JedisConnectionException ...

  2. 测试连接redis时报错redis.clients.jedis.exceptions.JedisConnectionException: Failed to create socket.

    解决方法 如果关注Redis的问题,有这么几个方面: 配置文件中应该注释69行的127地址:# bind 127.0.0.1 配置文件中应该修改修改88行为no:protected-mode no 然 ...

  3. redis.clients.jedis.exceptions.JedisConnectionException: java.net.ConnectException: Connection refus

    今天在连接redis时出现了一个奇怪的错误.如下: public class RedisTest {@Testpublic void redisTest(){// 连接RedisJedis jedis ...

  4. 一次redis连接配置修改引发的redis.clients.jedis.exceptions.JedisConnectionException: Unexpected end of stream.异常

    一次redis连接配置修改引发的redis.clients.jedis.exceptions.JedisConnectionException: Unexpected end of stream.异常 ...

  5. redis.clients.jedis.exceptions.JedisConnectionException: java.net.ConnectException: Connection refu

            今天在做Redis 测试的时候遇到一个错误,写一篇博客博客记录一下:          错误: redis.clients.jedis.exceptions.JedisConnecti ...

  6. 解决高并发下Redis连接失败redis.clients.jedis.exceptions.JedisConnectionException Attempting to read from a bro

    引出问题 当前Redis配置项 测压环境 出现的问题: redis.clients.jedis.exceptions.JedisConnectionException: Attempting to r ...

  7. redis.clients.jedis.exceptions.JedisConnectionException: Could not get a resource from the pool

    解决办法:调整JedisPoolConfig中maxActive为适合自己系统的阀值. <bean id="dataJedisPoolConfig" class=" ...

  8. springboot报错:Could not get a resource from the pool redis.clients.jedis.exceptions.JedisConnection

    运行项目时报错: 2022-04-15 19:27:54.052 ERROR 9676 --- [nio-8181-exec-1] o.a.c.c.C.[.[.[/].[dispatcherServl ...

  9. nested exception is redis.clients.jedis.exceptions.JedisDataException: NOAUTH Authentication requir

    springboot 1.5X 升级2.0时,redis 配置密码报错 org.springframework.dao.InvalidDataAccessApiUsageException: NOAU ...

  10. 【异常】redis.clients.jedis.exceptions.JedisDataException: ERR unknown command ‘PSETEX‘

    [异常]redis.clients.jedis.exceptions.JedisDataException: ERR unknown command 'PSETEX' 参考文章: (1)[异常]red ...

最新文章

  1. 没有数学何来计算机:论计算机起源的数学思想
  2. python语言中的多行注释符是_有没有一种方法可以在Python中创建多行注释? - python...
  3. CAN总线简明易懂教程(一)
  4. IR2104s半桥驱动使用经验
  5. [javaweb] servlet处理请求参数中文乱码的问题
  6. Scala代码案例:100以内的数求和,求出当和第一次大于20的当前数(循环中断机制)
  7. boost::sort模块实现spreadsort 64 位整数排序示例
  8. FireDAC 中文字段过滤问题
  9. 開發MOSS2007 Masterpage的一些經驗
  10. html5 防止脚本攻击,shell防ddos攻击脚本(二)
  11. 怎样学操作系统?一文带你掌握核心内容
  12. 荣耀30S首发新一代神U麒麟820 5G:GeekBench得分媲美骁龙855
  13. linux保存python文件_告诉Python将.txt文件保存到Linux上的某个目录 - python
  14. (八)构建一个Docker容器来训练Deep Fake Autoencoders
  15. 代码只要写得多,就能成为顶尖的架构师?
  16. 31.整数中1出现的次数(从1到n整数中1出现的次数)
  17. Eclipse ADT Bundle 整合包下载地址(百度网盘)
  18. 《Python和Pygame游戏开发指南》——导读
  19. linux只打包空目录,linux 打包当前文件夹下所有文件的方法
  20. 思科、华为等四大厂商网络工程师面试题汇总+解析(第1期)

热门文章

  1. 2017青岛网络赛 C - The Dominator of Strings(AC自动机)
  2. mysql count sending data_mysql查询sending data占用大量时间的问题处理
  3. 深入理解操作系统实验——bomb lab(phase_3)
  4. mysql 空格显示问号_空格变成问号
  5. 基于递归回溯算法实现八皇后游戏问题
  6. 初识Vue——八皇后小游戏
  7. 神秘的百度工业互联网,到底有多厉害?
  8. 基于JSP实现医院病历管理系统,程序员如何在工作中自我增值
  9. crate部署(crateDB)
  10. 阿里资深数据分析师回答那些关于数据分析师的最常见的几个问题