Skip to content

Commit

Permalink
Adding equals/hashcode to members that compose key for connection pool
Browse files Browse the repository at this point in the history
Signed-off-by: Paulo Lopes <pmlopes@gmail.com>
  • Loading branch information
pmlopes authored and vietj committed Sep 21, 2023
1 parent 820ca0b commit f141751
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 8 deletions.
22 changes: 19 additions & 3 deletions src/main/java/io/vertx/redis/client/impl/CommandImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,7 @@
import io.vertx.redis.client.impl.keys.KeyConsumer;

import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.*;

/**
* Implementation of the command metadata
Expand Down Expand Up @@ -139,4 +137,22 @@ public int iterateKeys(List<byte[]> args, KeyConsumer consumer) {
public String toString() {
return command;
}

@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
CommandImpl command1 = (CommandImpl) o;
// the command itself must be unique, the remaining properties are not relevant as they are metadata for the command
return Objects.equals(command, command1.command);
}

@Override
public int hashCode() {
return Objects.hash(command);
}
}
22 changes: 18 additions & 4 deletions src/main/java/io/vertx/redis/client/impl/RequestImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,7 @@
import io.vertx.redis.client.Request;

import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.*;

import static io.vertx.redis.client.impl.RESPEncoder.numToBytes;

Expand Down Expand Up @@ -202,4 +199,21 @@ public boolean valid() {
return -arity <= arglen;
}
}

@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
RequestImpl request = (RequestImpl) o;
return Objects.equals(cmd, request.cmd) && Objects.equals(args, request.args);
}

@Override
public int hashCode() {
return Objects.hash(cmd, args);
}
}
2 changes: 1 addition & 1 deletion tools/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"redis": "^2.8.0"
},
"scripts": {
"--prestart": "docker run --rm --net=host redis:latest",
"--prestart": "docker run --rm --net=host redis/redis-stack-server:7.0.6-RC8",
"start": "node commands.js"
}
}

0 comments on commit f141751

Please sign in to comment.