File tree Expand file tree Collapse file tree 6 files changed +52
-10
lines changed
main/java/redis/clients/jedis
test/java/redis/clients/jedis Expand file tree Collapse file tree 6 files changed +52
-10
lines changed Original file line number Diff line number Diff line change @@ -36,4 +36,12 @@ protected AbstractTransaction(CommandObjects commandObjects) {
3636 public Response <Long > waitReplicas (int replicas , long timeout ) {
3737 return appendCommand (commandObjects .waitReplicas (replicas , timeout ));
3838 }
39+
40+ public Response <Long > publish (String channel , String message ) {
41+ return appendCommand (commandObjects .publish (channel , message ));
42+ }
43+
44+ public Response <Long > publish (byte [] channel , byte [] message ) {
45+ return appendCommand (commandObjects .publish (channel , message ));
46+ }
3947}
Original file line number Diff line number Diff line change @@ -46,6 +46,13 @@ private static ClusterCommandObjects createClusterCommandObjects(RedisProtocol p
4646 return cco ;
4747 }
4848
49+ /**
50+ * This method must be called after constructor, if graph commands are going to be used.
51+ */
52+ public void prepareGraphCommands () {
53+ super .prepareGraphCommands (provider );
54+ }
55+
4956 @ Override
5057 public void close () {
5158 try {
@@ -65,10 +72,11 @@ protected Connection getConnection(HostAndPort nodeKey) {
6572 return provider .getConnection (nodeKey );
6673 }
6774
68- /**
69- * This method must be called after constructor, if graph commands are going to be used.
70- */
71- public void prepareGraphCommands () {
72- super .prepareGraphCommands (provider );
75+ public Response <Long > spublish (String channel , String message ) {
76+ return appendCommand (commandObjects .spublish (channel , message ));
77+ }
78+
79+ public Response <Long > spublish (byte [] channel , byte [] message ) {
80+ return appendCommand (commandObjects .spublish (channel , message ));
7381 }
7482}
Original file line number Diff line number Diff line change @@ -359,6 +359,9 @@ protected Object readProtocolWithCheckingBroken() {
359359
360360 try {
361361 return Protocol .read (inputStream , clientSideCache );
362+ // Object read = Protocol.read(inputStream);
363+ // System.out.println(redis.clients.jedis.util.SafeEncoder.encodeObject(read));
364+ // return read;
362365 } catch (JedisConnectionException exc ) {
363366 broken = true ;
364367 throw exc ;
Original file line number Diff line number Diff line change @@ -1024,6 +1024,18 @@ public void testEvalshaKeyAndArgWithBinary() {
10241024 }
10251025 }
10261026
1027+ @ Test
1028+ public void spublishInPipeline () {
1029+ try (JedisCluster jedis = new JedisCluster (nodes , DEFAULT_CLIENT_CONFIG )) {
1030+ ClusterPipeline pipelined = jedis .pipelined ();
1031+ Response <Long > p1 = pipelined .publish ("foo" , "bar" );
1032+ Response <Long > p2 = pipelined .publish ("foo" .getBytes (), "bar" .getBytes ());
1033+ pipelined .sync ();
1034+ assertEquals (0 , p1 .get ().longValue ());
1035+ assertEquals (0 , p2 .get ().longValue ());
1036+ }
1037+ }
1038+
10271039 @ Test
10281040 public void simple () { // TODO: move into 'redis.clients.jedis.commands.unified.cluster' package
10291041 try (JedisCluster jedis = new JedisCluster (nodes , DEFAULT_CLIENT_CONFIG )) {
Original file line number Diff line number Diff line change @@ -257,7 +257,7 @@ public void pipelineResponseWithinPipeline() {
257257 }
258258
259259 @ Test
260- public void pipelineWithPubSub () {
260+ public void publishInPipeline () {
261261 Pipeline pipelined = jedis .pipelined ();
262262 Response <Long > p1 = pipelined .publish ("foo" , "bar" );
263263 Response <Long > p2 = pipelined .publish ("foo" .getBytes (), "bar" .getBytes ());
Original file line number Diff line number Diff line change @@ -106,18 +106,29 @@ public void transaction() {
106106
107107 @ Test
108108 public void watch () {
109- List <Object > resp ;
110109 try (AbstractTransaction tx = jedis .transaction (false )) {
111110 assertEquals ("OK" , tx .watch ("mykey" , "somekey" ));
112111 tx .multi ();
113112
114113 jedis .set ("mykey" , "bar" );
115114
116115 tx .set ("mykey" , "foo" );
117- resp = tx .exec ();
116+ assertNull (tx .exec ());
117+
118+ assertEquals ("bar" , jedis .get ("mykey" ));
119+ }
120+ }
121+
122+ @ Test
123+ public void publishInTransaction () {
124+ try (AbstractTransaction tx = jedis .multi ()) {
125+ Response <Long > p1 = tx .publish ("foo" , "bar" );
126+ Response <Long > p2 = tx .publish ("foo" .getBytes (), "bar" .getBytes ());
127+ tx .exec ();
128+
129+ assertEquals (0 , p1 .get ().longValue ());
130+ assertEquals (0 , p2 .get ().longValue ());
118131 }
119- assertNull (resp );
120- assertEquals ("bar" , jedis .get ("mykey" ));
121132 }
122133
123134 @ Test
You can’t perform that action at this time.
0 commit comments