Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support AUTH2 argument to MIGRATE #2430

Merged
merged 6 commits into from
Mar 14, 2021
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions src/main/java/redis/clients/jedis/params/MigrateParams.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
package redis.clients.jedis.params;

import redis.clients.jedis.util.SafeEncoder;

import java.util.ArrayList;
import java.util.List;

public class MigrateParams extends Params {

private static final String COPY = "COPY";
private static final String REPLACE = "REPLACE";
private static final String AUTH = "AUTH";
private static final String AUTH2 = "AUTH2";

public MigrateParams() {
}
Expand All @@ -27,4 +33,32 @@ public MigrateParams auth(String password) {
addParam(AUTH, password);
return this;
}

public MigrateParams auth2(String username, String password) {
addParam(AUTH2, new String[] { username, password });
return this;
}

@Override
public byte[][] getByteParams() {
dengliming marked this conversation as resolved.
Show resolved Hide resolved
List<byte[]> byteParams = new ArrayList<>();

if (contains(COPY)) {
byteParams.add(SafeEncoder.encode(COPY));
}
if (contains(REPLACE)) {
byteParams.add(SafeEncoder.encode(REPLACE));
}
if (contains(AUTH)) {
byteParams.add(SafeEncoder.encode(AUTH));
byteParams.add(SafeEncoder.encode((String) getParam(AUTH)));
} else if (contains(AUTH2)) {
byteParams.add(SafeEncoder.encode(AUTH2));
String[] nameAndPass = (String[]) getParam(AUTH2);
byteParams.add(SafeEncoder.encode(nameAndPass[0]));
byteParams.add(SafeEncoder.encode(nameAndPass[1]));
}

return byteParams.toArray(new byte[byteParams.size()][]);
}
}
16 changes: 16 additions & 0 deletions src/test/java/redis/clients/jedis/tests/commands/MigrateTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,22 @@ public void migrateAuth() {
assertNull(jedis.get(bfoo));
}

@Test
public void migrateAuth2() {
dest.set("foo", "bar");
assertEquals("OK", dest.migrate(host, hnp.getPort(), 0, timeout,
new MigrateParams().auth2("acljedis", "fizzbuzz"), "foo"));
assertEquals("bar", jedis.get("foo"));
assertNull(dest.get("foo"));
sazzad16 marked this conversation as resolved.
Show resolved Hide resolved

// binary
dest.set(bfoo1, bbar1);
assertEquals("OK", dest.migrate(host, hnp.getPort(), 0, timeout,
new MigrateParams().auth2("acljedis", "fizzbuzz"), bfoo1));
assertEquals(bbar1, jedis.get(bfoo1));
assertNull(dest.get(bfoo1));
}

@Test
public void migrateCopyReplaceAuth() {
jedis.set("foo", "bar1");
Expand Down