NutzCN Logo
问答 redis 订阅提示错误
发布于 227天前 作者 Rekoe 242 次浏览 复制 上一个帖子 下一个帖子
标签: jedis redis

ioc 调用init的方法的时候加入了一个 过期监听时间
但提示这个错误

2017-01-08 18:19:11,553 [INFO][com.rekoe.service.RedisDao] - 开始监听Redis事件......
2017-01-08 18:19:11,603 [WARN][org.nutz.mvc.impl.processor.FailProcessor] - Error@/yvr/api/v1/redis :
redis.clients.jedis.exceptions.JedisDataException: ERR only (P)SUBSCRIBE / (P)UNSUBSCRIBE / QUIT allowed in this context
	at redis.clients.jedis.Protocol.processError(Protocol.java:127)
	at redis.clients.jedis.Protocol.process(Protocol.java:161)
	at redis.clients.jedis.Protocol.read(Protocol.java:215)
	at redis.clients.jedis.Connection.readProtocolWithCheckingBroken(Connection.java:340)
	at redis.clients.jedis.Connection.getIntegerReply(Connection.java:265)
	at redis.clients.jedis.Jedis.exists(Jedis.java:179)
	at com.rekoe.service.RedisDao.listPop(RedisDao.java:148)
	at com.rekoe.service.RedisDao$$NUTZAOP._aop_invoke(RedisDao.java:4)
	at org.nutz.aop.InterceptorChain.invoke(InterceptorChain.java:77)
	at org.nutz.aop.InterceptorChain.doChain(InterceptorChain.java:57)
	at org.nutz.integration.jedis.RedisInterceptor.filter(RedisInterceptor.java:25)
	at org.nutz.aop.InterceptorChain.doChain(InterceptorChain.java:60)
	at com.rekoe.service.RedisDao$$NUTZAOP.listPop(RedisDao.java:1)
	at com.rekoe.service.RedisDao.load(RedisDao.java:87)
	at com.rekoe.module.ApiModule.redis(ApiModule.java:81)
	at com.rekoe.module.ApiModule$$FASTCLASS._invoke(ApiModule.java:1)
	at org.nutz.lang.reflect.AbstractFastClass.invoke(AbstractFastClass.java:143)
	at org.nutz.lang.reflect.FastClassFactory.invoke(FastClassFactory.java:67)
	at org.nutz.mvc.impl.processor.MethodInvokeProcessor.process(MethodInvokeProcessor.java:27)
	at org.nutz.mvc.impl.processor.AbstractProcessor.doNext(AbstractProcessor.java:44)
	at org.nutz.mvc.impl.processor.AdaptorProcessor.process(AdaptorProcessor.java:33)
	at org.nutz.mvc.impl.processor.AbstractProcessor.doNext(AbstractProcessor.java:44)
	at org.nutz.mvc.impl.processor.ActionFiltersProcessor.process(ActionFiltersProcessor.java:58)
	at org.nutz.mvc.impl.processor.AbstractProcessor.doNext(AbstractProcessor.java:44)
	at org.nutz.integration.shiro.NutShiroProcessor.process(NutShiroProcessor.java:118)
	at org.nutz.mvc.impl.processor.AbstractProcessor.doNext(AbstractProcessor.java:44)
	at org.nutz.mvc.impl.processor.ModuleProcessor.process(ModuleProcessor.java:123)
	at org.nutz.mvc.impl.processor.AbstractProcessor.doNext(AbstractProcessor.java:44)
	at org.nutz.mvc.impl.processor.EncodingProcessor.process(EncodingProcessor.java:27)
	at org.nutz.mvc.impl.processor.AbstractProcessor.doNext(AbstractProcessor.java:44)
	at org.nutz.mvc.impl.processor.UpdateRequestAttributesProcessor.process(UpdateRequestAttributesProcessor.java:15)
	at org.nutz.mvc.impl.NutActionChain.doChain(NutActionChain.java:44)
	at org.nutz.mvc.impl.ActionInvoker.invoke(ActionInvoker.java:67)
	at org.nutz.mvc.ActionHandler.handle(ActionHandler.java:31)
	at org.nutz.mvc.NutFilter.doFilter(NutFilter.java:198)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
	at com.alibaba.druid.support.http.WebStatFilter.doFilter(WebStatFilter.java:123)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
	at org.apache.shiro.web.servlet.AbstractShiroFilter.executeChain(AbstractShiroFilter.java:449)
	at org.apache.shiro.web.servlet.AbstractShiroFilter$1.call(AbstractShiroFilter.java:365)
	at org.apache.shiro.subject.support.SubjectCallable.doCall(SubjectCallable.java:90)
	at org.apache.shiro.subject.support.SubjectCallable.call(SubjectCallable.java:83)
	at org.apache.shiro.subject.support.DelegatingSubject.execute(DelegatingSubject.java:383)
	at org.apache.shiro.web.servlet.AbstractShiroFilter.doFilterInternal(AbstractShiroFilter.java:362)
	at org.apache.shiro.web.servlet.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:125)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
	at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:222)
	at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123)
	at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
	at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:168)
	at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:99)
	at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
	at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:407)
	at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1002)
	at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:585)
	at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:310)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
	at java.lang.Thread.run(Thread.java:745)

code

@Aop("redis")
	public void init() {
		final Jedis jedis = jedis();
		new Thread() {
			public void run() {
				RedisEventListener listener = new RedisEventListener();
				logger.info("开始监听Redis事件......");
				jedis.psubscribe(listener, "__keyevent@0__:expired");
			}
		}.start();
	}
5 回复
public class RedisEventListener extends JedisPubSub {

	private static final Log logger = Logs.get();

	// 取得订阅的消息后的处理
	public void onMessage(String channel, String message) {
		// System.out.println(channel + "=" + message);
		logger.infof("收到redis事件onMessage:%s = %s", channel, message);
	}

	// 取得按表达式的方式订阅的消息后的处理
	public void onPMessage(String pattern, String channel, String message) {
		logger.infof("收到redis事件onPMessage:%s = %s = %s", pattern, channel, message);
	}

}

不可以这样啊

@Inject JedisPool jedisPool;
public void init() {
		new Thread() {
			public void run() {
				RedisEventListener listener = new RedisEventListener();
				logger.info("开始监听Redis事件......");
				jedisPool.getResource().psubscribe(listener, "__keyevent@0__:expired");
			}
		}.start();
}

难道 监听的加入 会有什么先后顺序?

jedis实例获取的问题

已解决
结帖

添加回复
请先登陆
回到顶部