New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
subscribe command doesn't work as expected #1341
Comments
I encountered the same problem also for psubscribe. |
Critical issue for me as well |
@varelasavela according to redis cluster spec clients can subscribe to any node and RedisCluster should forward notifications across the cluster http://redis.io/topics/cluster-spec#publishsubscribe. have you tried if this works outside Jedis? |
@marcosnils yes, I tried. Pub/sub works as described iin the spec in redis-cli and Jedis as well, but psubscribe works different. In redis-cli you should subscribe in each node to the pattern in order to catch the event. When I tried to do the same in Jedis, I got the event but after few seconds got exception which I copied to the body of my question |
It seems like |
@xetorthio IIUC @varelasavela has problems with |
@varelasavela this works for me final JedisCluster jc = new JedisCluster(new HostAndPort("localhost", 30001));
new Thread(new Runnable() {
@Override
public void run() {
jc.subscribe(new JedisPubSub() {
@Override
public void onMessage(String channel, String message) {
System.out.println(channel + " " + message);
}
@Override
public void onSubscribe(String channel, int subscribedChannels) {
System.out.println("Subscribed");
}
}, "__keyevent@0__:expired");
}
}).start();
for (int i = 0; i < 10000; i++) {
jc.publish("__keyevent@0__:expired", "test" + i);
} Is there a way to consistently reproduce the error you're getting? |
@varelasavela BTW psubscribe also works. final JedisCluster jc = new JedisCluster(new HostAndPort("localhost", 30001));
new Thread(new Runnable() {
@Override
public void run() {
jc.psubscribe(new JedisPubSub() {
@Override
public void onPSubscribe(String pattern, int subscribedChannels) {
System.out.println("Subscribed");
}
@Override
public void onPMessage(String pattern, String channel, String message) {
System.out.println(pattern + channel + message);
}
}, "*pepe*");
}
}).start();
for (int i = 0; i < 10000; i++) {
jc.publish("pepe"+i, "test" + i);
} |
@marcosnils
now, go to redis-cli |
@varelasavela I don't understand why Can you please describe the |
@marcosnils I will explain. |
@varelasavela got it. I missed the part where you were talking about keyspace notifications. This has been reported as a |
Closing due to redis/redis-doc#1367 |
Expected behavior
The implementation of jedisCluster is to pick random node and subscribe only to that node. So if the key is located on that node, it will work, but if it is located on other node , it will not work.
I tried to do the following:
I got this error after few seconds of working well:
redis.clients.jedis.exceptions.JedisException: Unknown message type: [B@37a326c7
at redis.clients.jedis.JedisPubSub.process(JedisPubSub.java:149)
at redis.clients.jedis.JedisPubSub.proceed(JedisPubSub.java:102)
at com.vp.configuration.KeyExpiredListener.proceed(KeyExpiredListener.java:32)
at redis.clients.jedis.Jedis.subscribe(Jedis.java:2628)
at java.lang.Thread.run(Thread.java:745)
Redis / Jedis Configuration
notify-keyspace-events : Ex
Jedis version:
2.8.1
Redis version:
3.2.1
Java version:
8
The text was updated successfully, but these errors were encountered: