背景

今天重新搭了个redis环境,用简单的代码去测试下是否正常,

@RunWith(SpringRunner.class)
@SpringBootTest
public class SpringbootRedisApplicationTests {@AutowiredStringRedisTemplate stringRedisTemplate;@Testpublic void saveString() {//保存字符串stringRedisTemplate.opsForValue().set("accountId","123456");Assert.assertEquals("123456",stringRedisTemplate.opsForValue().get("accountId"));}}

结果发现报如下异常:

org.springframework.data.redis.RedisSystemException: Redis exception; nested exception is io.lettuce.core.RedisException: io.lettuce.core.RedisConnectionException: 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 org.springframework.data.redis.connection.lettuce.LettuceExceptionConverter.convert(LettuceExceptionConverter.java:74)at org.springframework.data.redis.connection.lettuce.LettuceExceptionConverter.convert(LettuceExceptionConverter.java:41)at org.springframework.data.redis.PassThroughExceptionTranslationStrategy.translate(PassThroughExceptionTranslationStrategy.java:44)at org.springframework.data.redis.FallbackExceptionTranslationStrategy.translate(FallbackExceptionTranslationStrategy.java:42)at org.springframework.data.redis.connection.lettuce.LettuceConnection.convertLettuceAccessException(LettuceConnection.java:257)at org.springframework.data.redis.connection.lettuce.LettuceStringCommands.convertLettuceAccessException(LettuceStringCommands.java:718)at org.springframework.data.redis.connection.lettuce.LettuceStringCommands.set(LettuceStringCommands.java:143)at org.springframework.data.redis.connection.DefaultedRedisConnection.set(DefaultedRedisConnection.java:231)at org.springframework.data.redis.connection.DefaultStringRedisConnection.set(DefaultStringRedisConnection.java:917)at org.springframework.data.redis.core.DefaultValueOperations$3.inRedis(DefaultValueOperations.java:202)at org.springframework.data.redis.core.AbstractOperations$ValueDeserializingRedisCallback.doInRedis(AbstractOperations.java:59)at org.springframework.data.redis.core.RedisTemplate.execute(RedisTemplate.java:224)at org.springframework.data.redis.core.RedisTemplate.execute(RedisTemplate.java:184)at org.springframework.data.redis.core.AbstractOperations.execute(AbstractOperations.java:95)at org.springframework.data.redis.core.DefaultValueOperations.set(DefaultValueOperations.java:198)at com.eshare.SpringbootRedisApplicationTests.saveString(SpringbootRedisApplicationTests.java:21)at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)at java.lang.reflect.Method.invoke(Method.java:498)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.springframework.test.context.junit4.statements.RunBeforeTestExecutionCallbacks.evaluate(RunBeforeTestExecutionCallbacks.java:73)at org.springframework.test.context.junit4.statements.RunAfterTestExecutionCallbacks.evaluate(RunAfterTestExecutionCallbacks.java:83)at org.springframework.test.context.junit4.statements.RunBeforeTestMethodCallbacks.evaluate(RunBeforeTestMethodCallbacks.java:75)at org.springframework.test.context.junit4.statements.RunAfterTestMethodCallbacks.evaluate(RunAfterTestMethodCallbacks.java:86)at org.springframework.test.context.junit4.statements.SpringRepeat.evaluate(SpringRepeat.java:84)at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:251)at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:97)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.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCallbacks.java:61)at org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallbacks.java:70)at org.junit.runners.ParentRunner.run(ParentRunner.java:363)at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:190)at org.junit.runner.JUnitCore.run(JUnitCore.java:137)at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:68)at com.intellij.rt.execution.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:47)at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:242)at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:70)
Caused by: io.lettuce.core.RedisException: io.lettuce.core.RedisConnectionException: 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 io.lettuce.core.LettuceFutures.awaitOrCancel(LettuceFutures.java:125)at io.lettuce.core.FutureSyncInvocationHandler.handleInvocation(FutureSyncInvocationHandler.java:62)at io.lettuce.core.internal.AbstractInvocationHandler.invoke(AbstractInvocationHandler.java:80)at com.sun.proxy.$Proxy75.set(Unknown Source)at org.springframework.data.redis.connection.lettuce.LettuceStringCommands.set(LettuceStringCommands.java:141)... 39 more
Caused by: io.lettuce.core.RedisConnectionException: 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 io.lettuce.core.protocol.CommandHandler.onProtectedMode(CommandHandler.java:703)at io.lettuce.core.protocol.CommandHandler.consumeResponse(CommandHandler.java:689)at io.lettuce.core.protocol.CommandHandler.decode(CommandHandler.java:522)at io.lettuce.core.protocol.CommandHandler.channelRead(CommandHandler.java:508)at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:362)at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:348)at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:340)at io.netty.channel.ChannelInboundHandlerAdapter.channelRead(ChannelInboundHandlerAdapter.java:86)at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:362)at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:348)at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:340)at io.netty.channel.ChannelInboundHandlerAdapter.channelRead(ChannelInboundHandlerAdapter.java:86)at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:362)at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:348)at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:340)at io.netty.channel.DefaultChannelPipeline$HeadContext.channelRead(DefaultChannelPipeline.java:1434)at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:362)at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:348)at io.netty.channel.DefaultChannelPipeline.fireChannelRead(DefaultChannelPipeline.java:965)at io.netty.channel.nio.AbstractNioByteChannel$NioByteUnsafe.read(AbstractNioByteChannel.java:163)at io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:646)at io.netty.channel.nio.NioEventLoop.processSelectedKeysOptimized(NioEventLoop.java:581)at io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:498)at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:460)at io.netty.util.concurrent.SingleThreadEventExecutor$5.run(SingleThreadEventExecutor.java:884)at io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30)at java.lang.Thread.run(Thread.java:748)

解决方案

经排查,原来是启动的时候,没有启用redis.conf配置导致的,原有的启动命令是:

./redis-server

后来启动命令加上redis.conf配置就可以连接正常了

./redis-server ../redis.conf

Redis异常 | DENIED Redis is running in protected mode because protected mode is enabled相关推荐

  1. 2017.7.10 Redis报错:DENIED Redis is running in protected mode

    参考来自: java 客户端链接不上redis解决方案 DENIED Redis is running in protected mode 完整错误信息: 1 Caused by: redis.cli ...

  2. SpringBoot连接Redis服务出现DENIED Redis is running in protected mode because protected mode is enabled

    问题描述:SpringBoot连接Redis服务出现DENIED Redis is running in protected mode because protected mode is enable ...

  3. error) DENIED Redis is running in protected mode because protected mode is enabled报错

    官网地址:https://redis.io/download 官方安装文档如下: Installation Download, extract and compile Redis with: $ wg ...

  4. redis解决(DENIED Redis is running in protected mode because prote)

    早上一个应用日志打印报错信息: 在应用上telnet端口和ping都没有问题,为什么还获取不到值呢. 先安装一个redis客户端进行测试:yum -y install redis redis-cli ...

  5. (error) DENIED Redis is running in protected mode because protected mode is enabled

    Redis protected-mode 是3.2 之后加入的新特性,在Redis.conf的注释中,我们可以了解到,他的具体作用和启用条件 链接redis 时只能通过本地localhost (127 ...

  6. DENIED Redis is running in protected mode because protected mode is enabled

    如下所示,程序连接redis报错,根据错误信息,redis运行在受保护模式,需要redis命令行下作设置:config set protected-mode no. 设置protected-mode ...

  7. Redis异常:JedisConnectionException: All sentinels down, cannot determine where is mymaster master is

    1. 异常现象 Caused by: redis.clients.jedis.exceptions.JedisConnectionException: All sentinels down, cann ...

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

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

  9. Docker安装Redis,Spring Boot使用Redis,解决Redis发生的类型转换异常

    Docker安装Redis(如果已安装请跳过这一步) 1.拉取Redis镜像(默认最新版本) docker pull redis 如果下载比较慢的话建议配置阿里云镜像 查看阿里云镜像:阿里云官网--& ...

最新文章

  1. 如何利用K-Means将文件夹中图像进行分类?
  2. PHP — Cookie and Session篇
  3. 线程同步--线程间通信
  4. (转)数据库查询速度慢的原因
  5. mysql 5.6.26 编译安装
  6. 利用计算机的说课稿,《计算机的发展与应用》说课稿
  7. Junit介绍与实现
  8. BugFree的安装
  9. ue4 命名插件_实时渲染模拟每根头发丝!新版UE4在实时毛发方面的实验性新功能...
  10. SLAM专题(8)卡尔曼滤波和扩展卡尔曼滤波 原理与应用
  11. 8086/8088,80286,80386的CPU寄存器
  12. java thrift使用指南_Thrift使用指南
  13. 机器人三星云顶之弈_机器码|云顶之弈10.16三星机器人加强介绍-云顶之弈10.16三星机器人加强了吗_234游戏网...
  14. Java简单日记本项目
  15. 008.UG_NX自由曲面
  16. 浙江大学-翁凯 C语言进阶,编程题
  17. 项立刚谈鸿蒙操作系统,项立刚:鸿蒙OS一定会成为划时代意义的操作系统人民邮电报0...
  18. 项目实战 航班飞行网图分析
  19. CKEditor插件的使用
  20. xml 学习(教训啊,还是要实战代码

热门文章

  1. 在Windows系统浏览器中访问虚拟机CentOS里面Docker容器运行nginx服务器
  2. 安装Python3环境和pip3
  3. 分布式场景下的并发安全问题,收割快手,字节,百度,美团的Offer之旅
  4. 用python批量下载网络图片_用python批量下载图片
  5. 复习笔记:数据库填空题
  6. 搞点Python骚操作,自动美化excel表格
  7. ipad iphone源地址
  8. videojs播放器插件
  9. 阿里飞冰 Img组件绑定事件无效
  10. 计算机软件硬件基础知识,计算机软硬件基础知识