背景

今天重新搭了个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. Android开发之android_apk 在线安装(源代码分享)
  2. asp 取数据 计算_ASP.NET Core 简介
  3. 大型网站架构设计系列总结
  4. 计算机计算资源估计,项目时间管理中的计算题三点估算和关键路径法
  5. 基于Matlab----MSK调制与解调
  6. unity, itween, closed path
  7. 最全的软件开发报价标准
  8. 一个很有趣的游戏(看谁的名字打架厉害)
  9. ubuntu18使用wine安装TIM和微信
  10. Windows安装Redis新手教程
  11. 【网络】TCP报文头部
  12. 赴日java常问问题_赴日软件工程师java笔试题
  13. 基于TLC5615的多路可调数控直流稳压电源,51单片机,含Proteus仿真和C代码等
  14. 基于C++和OpenCV的中心线提取算法
  15. 假如生产环境出现CPU占用过高,如何排查与定位
  16. [MySQL进阶]——索引的数据结构
  17. 【JavaScript】时间日期,月日小于10的前面补0(新方法padStart)
  18. 全球隔离,生出不少坏毛病
  19. 第三人称计算机获奖感言,玄彬获奖感言感谢女友孙艺珍 惹众网友羡慕
  20. 大法师(简单题总结)

热门文章

  1. java记忆力,提高记忆力的方法
  2. Clos Network 与 Leaf Spine 架构
  3. 利用jQuery制作一个普通网页需要注意多少细节之电梯导航
  4. 计算机设置和美化表格优质课,信息技术教案第三节:Excel工作表的编辑与美化.doc...
  5. Serializable解析
  6. layui中iframe自适应高度
  7. 详细实现ESP8266WIFI时钟(基于51单片机)
  8. @Pattern进行正则校验
  9. AEO认证辅导,海关要向满足该标准的商界提供相应的便利
  10. CSS3:动画、flexbox、响应式设计、网格布局