Skip to content

Commit

Permalink
Address code review comments
Browse files Browse the repository at this point in the history
- Restore public Transaction constructor that was removed
- Use Connection.executeCommand instead of Connection.sendCommand
  • Loading branch information
R-J Lim committed Mar 17, 2024
1 parent 872fcfd commit 571ed52
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 8 deletions.
8 changes: 4 additions & 4 deletions src/main/java/redis/clients/jedis/CommandObjects.java
Original file line number Diff line number Diff line change
Expand Up @@ -4259,12 +4259,12 @@ public final CommandObject<Object> tFunctionCallAsync(String library, String fun
// RedisGears commands

// Transaction commands
public final CommandObject<Object> watch(String... keys) {
return new CommandObject<>(commandArguments(WATCH).keys((Object[]) keys), BuilderFactory.RAW_OBJECT);
public final CommandObject<String> watch(String... keys) {
return new CommandObject<>(commandArguments(WATCH).keys((Object[]) keys), BuilderFactory.STRING);
}

public final CommandObject<Object> watch(byte[]... keys) {
return new CommandObject<>(commandArguments(WATCH).keys((Object[]) keys), BuilderFactory.RAW_OBJECT);
public final CommandObject<String> watch(byte[]... keys) {
return new CommandObject<>(commandArguments(WATCH).keys((Object[]) keys), BuilderFactory.STRING);
}
// Transaction commands

Expand Down
22 changes: 18 additions & 4 deletions src/main/java/redis/clients/jedis/Transaction.java
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ public Transaction(Connection connection, boolean doMulti) {
this(connection, new CommandObjects(), doMulti, false);
}


/**
* Creates a new transaction.
*
Expand All @@ -72,6 +73,21 @@ public Transaction(Connection connection, boolean doMulti) {
* @param doMulti {@code false} should be set to enable manual WATCH, UNWATCH and MULTI
* @param closeConnection should the 'connection' be closed when 'close()' is called?
*/
public Transaction(Connection connection, boolean doMulti, boolean closeConnection) {
this(connection, new CommandObjects(), doMulti, closeConnection);
}

/**
* Creates a new transaction.
*
* A user wanting to WATCH/UNWATCH keys followed by a call to MULTI ({@link #multi()}) it should
* be {@code doMulti=false}.
*
* @param connection connection
* @param commandObjects commandObjects
* @param doMulti {@code false} should be set to enable manual WATCH, UNWATCH and MULTI
* @param closeConnection should the 'connection' be closed when 'close()' is called?
*/
public Transaction(Connection connection, CommandObjects commandObjects, boolean doMulti, boolean closeConnection) {
super(commandObjects);
this.connection = connection;
Expand All @@ -91,16 +107,14 @@ public final void multi() {

@Override
public String watch(final String... keys) {
connection.sendCommand(commandObjects.watch(keys).getArguments());
String status = connection.getStatusCodeReply();
String status = connection.executeCommand(commandObjects.watch(keys));
inWatch = true;
return status;
}

@Override
public String watch(final byte[]... keys) {
connection.sendCommand(commandObjects.watch(keys).getArguments());
String status = connection.getStatusCodeReply();
String status = connection.executeCommand(commandObjects.watch(keys));
inWatch = true;
return status;
}
Expand Down

0 comments on commit 571ed52

Please sign in to comment.