Skip to content

Commit

Permalink
Bind byte arrays as keys using command interfaces and a binary codec #…
Browse files Browse the repository at this point in the history
  • Loading branch information
mp911de committed Oct 12, 2017
1 parent a882857 commit 9118137
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
6 changes: 5 additions & 1 deletion src/main/java/io/lettuce/core/dynamic/ParameterBinder.java
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,11 @@ private <K, V> void bind(CommandArgs<K, V> args, RedisCodec<K, V> codec, Object
}

if (argument instanceof byte[]) {
args.add((byte[]) argument);
if (index != -1 && accessor.isKey(index)) {
args.addKey((K) argument);
} else {
args.add((byte[]) argument);
}
return;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,18 @@ public void sync() {
assertThat(api.getAsBytes("key")).isEqualTo("value".getBytes());
}

@Test
public void shouldRouteBinaryKey() {

connection.sync().set(key, value);

RedisCommandFactory factory = new RedisCommandFactory(connection);

SynchronousCommands api = factory.getCommands(SynchronousCommands.class);

assertThat(api.get(key.getBytes())).isEqualTo(value.getBytes());
}

@Test
public void mgetAsValues() {

Expand All @@ -98,7 +110,9 @@ public void mgetAsValues() {
assertThat(values.get(0)).isEqualTo(Value.just(value));
}

static interface SynchronousCommands extends Commands {
interface SynchronousCommands extends Commands {

byte[] get(byte[] key);

String get(String key);

Expand Down

0 comments on commit 9118137

Please sign in to comment.