嵌入式 redis 无法启动 - ERR Unsupported CONFIG parameter: notify-keyspace-events

Posted

技术标签:

【中文标题】嵌入式 redis 无法启动 - ERR Unsupported CONFIG parameter: notify-keyspace-events【英文标题】:Embedded redis can't start - ERR Unsupported CONFIG parameter: notify-keyspace-events 【发布时间】:2016-07-10 17:10:17 【问题描述】:

我使用的是 Embedded-redis 0.6 版本和 spring-session-data-redis 1.0.1.RELEASE。使用 mvn spring-boot:run 命令执行 spring boot 后,tomcat 服务器启动,但嵌入式 redis 立即抛出以下异常(请参阅下面的完整堆栈跟踪):

redis.clients.jedis.exceptions.JedisDataException: ERR Unsupported CONFIG parameter: notify-keyspace-events

我该如何解决这个问题?

我的 pom.xml:

<dependency>
    <groupId>org.springframework.session</groupId>
    <artifactId>spring-session-data-redis</artifactId>
    <version>1.0.1.RELEASE</version> 
</dependency>
<dependency>
    <groupId>com.github.kstyrc</groupId>
    <artifactId>embedded-redis</artifactId>
    <version>0.6</version>
</dependency>

完整的堆栈跟踪:

Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'enableRedisKeyspaceNotificationsInitializer' defined in class path resource [org/springframework/session/data/redis/config/annotation/web/http/RedisHttpSessionConfiguration.class]: Invocation of init method failed; nested exception is org.springframework.dao.InvalidDataAccessApiUsageException: ERR Unsupported CONFIG parameter: notify-keyspace-events; nested exception is redis.clients.jedis.exceptions.JedisDataException: ERR Unsupported CONFIG parameter: notify-keyspace-events
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1578)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:545)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:482)
    at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306)
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302)
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197)
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:772)
    at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:839)
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:538)
    at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:118)
    at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:766)
    at org.springframework.boot.SpringApplication.createAndRefreshContext(SpringApplication.java:361)
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:307)
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1191)
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1180)
    at com.springbootapp.config.Application.main(Application.java:16)
    ... 6 more
Caused by: org.springframework.dao.InvalidDataAccessApiUsageException: ERR Unsupported CONFIG parameter: notify-keyspace-events; nested exception is redis.clients.jedis.exceptions.JedisDataException: ERR Unsupported CONFIG parameter: notify-keyspace-events
    at org.springframework.data.redis.connection.jedis.JedisExceptionConverter.convert(JedisExceptionConverter.java:44)
    at org.springframework.data.redis.connection.jedis.JedisExceptionConverter.convert(JedisExceptionConverter.java:36)
    at org.springframework.data.redis.PassThroughExceptionTranslationStrategy.translate(PassThroughExceptionTranslationStrategy.java:37)
    at org.springframework.data.redis.FallbackExceptionTranslationStrategy.translate(FallbackExceptionTranslationStrategy.java:37)
    at org.springframework.data.redis.connection.jedis.JedisConnection.convertJedisAccessException(JedisConnection.java:210)
    at org.springframework.data.redis.connection.jedis.JedisConnection.setConfig(JedisConnection.java:633)
    at org.springframework.session.data.redis.config.ConfigureNotifyKeyspaceEventsAction.configure(ConfigureNotifyKeyspaceEventsAction.java:63)
    at org.springframework.session.data.redis.config.annotation.web.http.RedisHttpSessionConfiguration$EnableRedisKeyspaceNotificationsInitializer.afterPropertiesSet(RedisHttpSessionConfiguration.java:167)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1637)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1574)
    ... 22 more
Caused by: redis.clients.jedis.exceptions.JedisDataException: ERR Unsupported CONFIG parameter: notify-keyspace-events
    at redis.clients.jedis.Protocol.processError(Protocol.java:117)
    at redis.clients.jedis.Protocol.process(Protocol.java:151)
    at redis.clients.jedis.Protocol.read(Protocol.java:205)
    at redis.clients.jedis.Connection.readProtocolWithCheckingBroken(Connection.java:297)
    at redis.clients.jedis.Connection.getStatusCodeReply(Connection.java:196)
    at redis.clients.jedis.Jedis.configSet(Jedis.java:2575)
    at org.springframework.data.redis.connection.jedis.JedisConnection.setConfig(JedisConnection.java:631)
    ... 26 more

【问题讨论】:

【参考方案1】:

错误通常发生在以下两种情况之一:

Redis 版本太旧

这似乎是最有可能的答案。来自the documentation:

要使示例正常工作,您必须在 localhost 上安装 Redis 2.8+ 并且 使用默认端口(6379)运行它。或者,您可以更新 JedisConnectionFactory 指向一个 Redis 服务器。

如果您不关心接收事件,您可以禁用creating a ConfigureRedisAction Bean 设置的键空间通知:

@Bean
public static ConfigureRedisAction configureRedisAction() 
    return ConfigureRedisAction.NO_OP;

或 XML

<util:constant
    static-field="org.springframework.session.data.redis.config.ConfigureRedisAction.NO_OP"/>

或者,确保您运行的是 Redis 2.8+。

您的 Redis 实例已禁用或重命名配置命令

嵌入式实例不太可能出现这种情况,因为默认配置会如此。来自文档:

如果你使用@EnableRedisHttpSession SessionMessageListener 并启用必要的 Redis Keyspace 事件 自动地。但是,在安全的 Redis 环境中,配置 命令被禁用。这意味着 Spring Session 无法配置 Redis Keyspace 事件为您服务。禁用自动配置 将 ConfigureRedisAction.NO_OP 添加为 bean。

例如,Java 配置可以使用以下内容:

@Bean
public static ConfigureRedisAction configureRedisAction() 
    return ConfigureRedisAction.NO_OP;

或 XML

<util:constant
    static-field="org.springframework.session.data.redis.config.ConfigureRedisAction.NO_OP"/>

【讨论】:

我使用的是嵌入式redis配置 是否有任何新版本可用于 Embedded-redis 配置,不需要 NO OP 设置,我的 pom.xml 依赖项已列出 Spring Session 停止使用嵌入式 Redis,因为它在现代版本和在所有操作系统上都不太稳定。我认为您最好的选择是切换到外部 Redis 实例。 从哪里下载windows的redis服务器,我可以配置redis实例从内部转移到外部redis实例 来自 Redis 下载页面“Redis 项目不正式支持 Windows。但是,Microsoft Open Tech 小组开发和维护了这个面向 Win64 的 Windows 端口。” github.com/MSOpenTech/redis 您可以使用 Spring Environment 抽象来外部化 Redis 指向的配置。如果您在这个问题上需要帮助,可能需要另一个问题(如果您使用的是 JavaConfig、XML Config 或 Spring Boot,请提供)

以上是关于嵌入式 redis 无法启动 - ERR Unsupported CONFIG parameter: notify-keyspace-events的主要内容,如果未能解决你的问题,请参考以下文章

Redis SAVE 命令 返回 ERR

Cognos CFG-ERR-0103 无法启动 IBM Cognos 服务

Redis报错:ERR This instance has cluster support disabled

生产redis client 链接报:ERR max number of clients reached 含义: 达到最大客户端数错误

System.err:调用 js 方法 onCreate 失败 - System.err:错误:缺少主条目。应用程序无法启动。验证应用引导程序

java 启动嵌入式redis进行测试