博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Spring session redis ERR unknown command 'CONFIG'
阅读量:6509 次
发布时间:2019-06-24

本文共 7801 字,大约阅读时间需要 26 分钟。

部署线上服务启动报错

redis.clients.jedis.exceptions.JedisDataException: ERR unknown command 'CONFIG'

Redis CONFIG GET命令是用来读取运行Redis服务器的配置参数。并非所有的配置参数在Redis2.4支持,而Redis2.6可以读取使用此命令的服务器的整体配置。

之前开发环境的redis都是自己部署的,权限都很大,所以程序也没报什么异常。现在生产环境是由运维管理,redis也是运维提供的一个2.8。

根据错误提示,直接redis-cli连上redis去执行Config命令

10.xx:6379> CONFIG GET parameter (error) ERR unknown command 'CONFIG'

确定了没有放开权限,就只能看能否不用这个命令了。

发现是spring-session-redis需要使用Keyspace notifications这个功能。

在 Redis 的 2.8.0 版本之后,其推出了一个新的特性——键空间消息(Redis Keyspace Notifications)……

键空间通知,允许Redis客户端从“发布/订阅”通道中建立订阅关系,以便客户端能够在Redis中的数据因某种方式受到影响时收到相应事件。……

在GitHub上看到有issues

具体解决方案:

  1. 开启redis的Keyspace notifications功能,重启

    notify-keyspace-events Ex
  2. 关闭Spring-session中对CONFIG的操作

    在xml里加上:

    或者

    @Beanpublic static ConfigureRedisAction configureRedisAction() {return ConfigureRedisAction.NO_OP;}

注意:

如果采用XML配置的方式,很有可能需要引入 util标签

spring xml 有顺序要求,xmls:util在最后,xsi里也是。


验证 notify-keyspace-events

打开一个redis连接

10.xx.xx.xx:6379> psubscribe '__key*__:*'Reading messages... (press Ctrl-C to quit)1) "psubscribe"2) "__key*__:*"3) (integer) 1

在另一个redis连接,设置一个短时间过期的key

10.xx.xx.xx:6379> set ZHANG LONG px 20OK

第一个连接则会收到事件消息

10.xx.xx.xx:6379> psubscribe '__key*__:*'Reading messages... (press Ctrl-C to quit)1) "psubscribe"2) "__key*__:*"3) (integer) 11) "pmessage"2) "__key*__:*"3) "__keyevent@0__:expired"4) "ZHANG"

异常信息:

12-Sep-2017 21:28:17.592 SEVERE [localhost-startStop-1] org.apache.catalina.core.StandardContext.listenerStart Exception sending context initialized event to listener instance of class org.springframework.web.context.ContextLoaderListener 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 java.lang.IllegalStateException: Unable to configure Redis to keyspace notifications. See http://docs.spring.io/spring-session/docs/current/reference/html5/#api-redisoperationssessionrepository-sessiondestroyedevent        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1628)        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:555)        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:483)        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:761)        at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:866)        at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:542)        at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:443)        at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:325)        at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:107)        at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4754)        at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5216)        at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)        at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:752)        at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:728)        at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:734)        at org.apache.catalina.startup.HostConfig.deployWAR(HostConfig.java:952)        at org.apache.catalina.startup.HostConfig$DeployWar.run(HostConfig.java:1823)        at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)        at java.util.concurrent.FutureTask.run(FutureTask.java:266)        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)        at java.lang.Thread.run(Thread.java:748)Caused by: java.lang.IllegalStateException: Unable to configure Redis to keyspace notifications. See http://docs.spring.io/spring-session/docs/current/reference/html5/#api-redisoperationssessionrepository-sessiondestroyedevent        at org.springframework.session.data.redis.config.ConfigureNotifyKeyspaceEventsAction.getNotifyOptions(ConfigureNotifyKeyspaceEventsAction.java:81)        at org.springframework.session.data.redis.config.ConfigureNotifyKeyspaceEventsAction.configure(ConfigureNotifyKeyspaceEventsAction.java:55)        at org.springframework.session.data.redis.config.annotation.web.http.RedisHttpSessionConfiguration$EnableRedisKeyspaceNotificationsInitializer.afterPropertiesSet(RedisHttpSessionConfiguration.java:251)        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1687)        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1624)        ... 25 moreCaused by: org.springframework.dao.InvalidDataAccessApiUsageException: ERR unknown command 'CONFIG'; nested exception is redis.clients.jedis.exceptions.JedisDataException: ERR unknown command 'CONFIG'        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.getConfig(JedisConnection.java:571)        at org.springframework.session.data.redis.config.ConfigureNotifyKeyspaceEventsAction.getNotifyOptions(ConfigureNotifyKeyspaceEventsAction.java:74)        ... 29 more        Caused by: redis.clients.jedis.exceptions.JedisDataException: ERR unknown command 'CONFIG'        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.getBinaryMultiBulkReply(Connection.java:233)        at redis.clients.jedis.Connection.getMultiBulkReply(Connection.java:226)        at redis.clients.jedis.Jedis.configGet(Jedis.java:2578)        at org.springframework.data.redis.connection.jedis.JedisConnection.getConfig(JedisConnection.java:569)        ... 30 more

转载于:https://www.cnblogs.com/coderzl/p/7512644.html

你可能感兴趣的文章
dtoj#4299. 图(graph)
查看>>
换用代理IP的Webbrowser方法
查看>>
【视频编解码·学习笔记】7. 熵编码算法:基础知识 & 哈夫曼编码
查看>>
MySql 查询表字段数
查看>>
怎么获得combobox的valueField值
查看>>
浅谈网络协议(四) IP的由来--DHCP与PXE
查看>>
jre与jdk的区别
查看>>
全景图的种类
查看>>
git 维护
查看>>
jfinal框架下使用c3P0连接池连接sql server 2008
查看>>
struts2中使用标签操作静态方法等
查看>>
熬夜写了一个小游戏,向SpaceX聊表敬意
查看>>
apache 开启 gzip 压缩服务
查看>>
python mysql
查看>>
开源 免费 java CMS - FreeCMS1.5-建站向导
查看>>
jquery 1.6以上版本 全选
查看>>
AppCan 学习
查看>>
flask框架
查看>>
《疯狂Java讲义》学习笔记(十)异常处理
查看>>
ELK 5.x日志分析 (二) Elasticserach 5.2 安装
查看>>