diff --git a/src/main/java/redis/clients/jedis/AbstractTransaction.java b/src/main/java/redis/clients/jedis/AbstractTransaction.java index 2a551224fa..a436907540 100644 --- a/src/main/java/redis/clients/jedis/AbstractTransaction.java +++ b/src/main/java/redis/clients/jedis/AbstractTransaction.java @@ -36,4 +36,12 @@ protected AbstractTransaction(CommandObjects commandObjects) { public Response waitReplicas(int replicas, long timeout) { return appendCommand(commandObjects.waitReplicas(replicas, timeout)); } + + public Response publish(String channel, String message) { + return appendCommand(commandObjects.publish(channel, message)); + } + + public Response publish(byte[] channel, byte[] message) { + return appendCommand(commandObjects.publish(channel, message)); + } } diff --git a/src/main/java/redis/clients/jedis/ClusterPipeline.java b/src/main/java/redis/clients/jedis/ClusterPipeline.java index 0c850c8ed8..a122b41688 100644 --- a/src/main/java/redis/clients/jedis/ClusterPipeline.java +++ b/src/main/java/redis/clients/jedis/ClusterPipeline.java @@ -46,6 +46,13 @@ private static ClusterCommandObjects createClusterCommandObjects(RedisProtocol p return cco; } + /** + * This method must be called after constructor, if graph commands are going to be used. + */ + public void prepareGraphCommands() { + super.prepareGraphCommands(provider); + } + @Override public void close() { try { @@ -65,10 +72,11 @@ protected Connection getConnection(HostAndPort nodeKey) { return provider.getConnection(nodeKey); } - /** - * This method must be called after constructor, if graph commands are going to be used. - */ - public void prepareGraphCommands() { - super.prepareGraphCommands(provider); + public Response spublish(String channel, String message) { + return appendCommand(commandObjects.spublish(channel, message)); + } + + public Response spublish(byte[] channel, byte[] message) { + return appendCommand(commandObjects.spublish(channel, message)); } } diff --git a/src/main/java/redis/clients/jedis/Connection.java b/src/main/java/redis/clients/jedis/Connection.java index 3bd5b56bf6..c41d897c4d 100644 --- a/src/main/java/redis/clients/jedis/Connection.java +++ b/src/main/java/redis/clients/jedis/Connection.java @@ -359,6 +359,9 @@ protected Object readProtocolWithCheckingBroken() { try { return Protocol.read(inputStream, clientSideCache); +// Object read = Protocol.read(inputStream); +// System.out.println(redis.clients.jedis.util.SafeEncoder.encodeObject(read)); +// return read; } catch (JedisConnectionException exc) { broken = true; throw exc; diff --git a/src/test/java/redis/clients/jedis/ClusterPipeliningTest.java b/src/test/java/redis/clients/jedis/ClusterPipeliningTest.java index ff196ec4ea..2edcb67456 100644 --- a/src/test/java/redis/clients/jedis/ClusterPipeliningTest.java +++ b/src/test/java/redis/clients/jedis/ClusterPipeliningTest.java @@ -1024,6 +1024,18 @@ public void testEvalshaKeyAndArgWithBinary() { } } + @Test + public void spublishInPipeline() { + try (JedisCluster jedis = new JedisCluster(nodes, DEFAULT_CLIENT_CONFIG)) { + ClusterPipeline pipelined = jedis.pipelined(); + Response p1 = pipelined.publish("foo", "bar"); + Response p2 = pipelined.publish("foo".getBytes(), "bar".getBytes()); + pipelined.sync(); + assertEquals(0, p1.get().longValue()); + assertEquals(0, p2.get().longValue()); + } + } + @Test public void simple() { // TODO: move into 'redis.clients.jedis.commands.unified.cluster' package try (JedisCluster jedis = new JedisCluster(nodes, DEFAULT_CLIENT_CONFIG)) { diff --git a/src/test/java/redis/clients/jedis/PipeliningTest.java b/src/test/java/redis/clients/jedis/PipeliningTest.java index 9340f366db..7df000c7a3 100644 --- a/src/test/java/redis/clients/jedis/PipeliningTest.java +++ b/src/test/java/redis/clients/jedis/PipeliningTest.java @@ -257,7 +257,7 @@ public void pipelineResponseWithinPipeline() { } @Test - public void pipelineWithPubSub() { + public void publishInPipeline() { Pipeline pipelined = jedis.pipelined(); Response p1 = pipelined.publish("foo", "bar"); Response p2 = pipelined.publish("foo".getBytes(), "bar".getBytes()); diff --git a/src/test/java/redis/clients/jedis/commands/unified/pooled/PooledMiscellaneousTest.java b/src/test/java/redis/clients/jedis/commands/unified/pooled/PooledMiscellaneousTest.java index 5c66363345..d6feb05fa3 100644 --- a/src/test/java/redis/clients/jedis/commands/unified/pooled/PooledMiscellaneousTest.java +++ b/src/test/java/redis/clients/jedis/commands/unified/pooled/PooledMiscellaneousTest.java @@ -106,7 +106,6 @@ public void transaction() { @Test public void watch() { - List resp; try (AbstractTransaction tx = jedis.transaction(false)) { assertEquals("OK", tx.watch("mykey", "somekey")); tx.multi(); @@ -114,10 +113,22 @@ public void watch() { jedis.set("mykey", "bar"); tx.set("mykey", "foo"); - resp = tx.exec(); + assertNull(tx.exec()); + + assertEquals("bar", jedis.get("mykey")); + } + } + + @Test + public void publishInTransaction() { + try (AbstractTransaction tx = jedis.multi()) { + Response p1 = tx.publish("foo", "bar"); + Response p2 = tx.publish("foo".getBytes(), "bar".getBytes()); + tx.exec(); + + assertEquals(0, p1.get().longValue()); + assertEquals(0, p2.get().longValue()); } - assertNull(resp); - assertEquals("bar", jedis.get("mykey")); } @Test