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 for ACL SAVE/LOAD commands #2418

Merged
merged 5 commits into from
Mar 11, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
8 changes: 8 additions & 0 deletions src/main/java/redis/clients/jedis/BinaryClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -1463,6 +1463,14 @@ public void aclDelUser(final byte[] name) {
sendCommand(ACL, Keyword.DELUSER.getRaw(), name);
}

public void aclLoad() {
sendCommand(ACL, Keyword.LOAD.getRaw());
}

public void aclSave() {
sendCommand(ACL, Keyword.SAVE.getRaw());
}

private List<byte[]> convertGeoCoordinateMapToByteArrays(
final Map<byte[], GeoCoordinate> memberCoordinateMap) {
List<byte[]> args = new ArrayList<>(memberCoordinateMap.size() * 3);
Expand Down
62 changes: 38 additions & 24 deletions src/main/java/redis/clients/jedis/BinaryJedis.java
Original file line number Diff line number Diff line change
Expand Up @@ -1840,14 +1840,14 @@ public Long sunionstore(final byte[] dstkey, final byte[]... keys) {
* Return the difference between the Set stored at key1 and all the Sets key2, ..., keyN
* <p>
* <b>Example:</b>
*
*
* <pre>
* key1 = [x, a, b, c]
* key2 = [c]
* key3 = [a, d]
* SDIFF key1,key2,key3 =&gt; [x, b]
* </pre>
*
*
* Non existing keys are considered like empty sets.
* <p>
* <b>Time complexity:</b>
Expand Down Expand Up @@ -2205,65 +2205,65 @@ public List<byte[]> sort(final byte[] key) {
* <b>examples:</b>
* <p>
* Given are the following sets and key/values:
*
*
* <pre>
* x = [1, 2, 3]
* y = [a, b, c]
*
*
* k1 = z
* k2 = y
* k3 = x
*
*
* w1 = 9
* w2 = 8
* w3 = 7
* </pre>
*
*
* Sort Order:
*
*
* <pre>
* sort(x) or sort(x, sp.asc())
* -&gt; [1, 2, 3]
*
*
* sort(x, sp.desc())
* -&gt; [3, 2, 1]
*
*
* sort(y)
* -&gt; [c, a, b]
*
*
* sort(y, sp.alpha())
* -&gt; [a, b, c]
*
*
* sort(y, sp.alpha().desc())
* -&gt; [c, a, b]
* </pre>
*
*
* Limit (e.g. for Pagination):
*
*
* <pre>
* sort(x, sp.limit(0, 2))
* -&gt; [1, 2]
*
*
* sort(y, sp.alpha().desc().limit(1, 2))
* -&gt; [b, a]
* </pre>
*
*
* Sorting by external keys:
*
*
* <pre>
* sort(x, sb.by(w*))
* -&gt; [3, 2, 1]
*
*
* sort(x, sb.by(w*).desc())
* -&gt; [1, 2, 3]
* </pre>
*
*
* Getting external keys:
*
*
* <pre>
* sort(x, sp.by(w*).get(k*))
* -&gt; [x, y, z]
*
*
* sort(x, sp.by(w*).get(#).get(k*))
* -&gt; [3, x, 2, y, 1, z]
* </pre>
Expand Down Expand Up @@ -3198,7 +3198,7 @@ public String shutdown() {
* <b>Format of the returned String:</b>
* <p>
* All the fields are in the form field:value
*
*
* <pre>
* edis_version:0.07
* connected_clients:1
Expand All @@ -3211,7 +3211,7 @@ public String shutdown() {
* uptime_in_seconds:25
* uptime_in_days:0
* </pre>
*
*
* <b>Notes</b>
* <p>
* used_memory is returned in bytes, and is the total number of bytes allocated by the program
Expand Down Expand Up @@ -3293,7 +3293,7 @@ public String slaveofNoOne() {
* are reported as a list of key-value pairs.
* <p>
* <b>Example:</b>
*
*
* <pre>
* $ redis-cli config get '*'
* 1. "dbfilename"
Expand All @@ -3308,7 +3308,7 @@ public String slaveofNoOne() {
* 10. "everysec"
* 11. "save"
* 12. "3600 1 300 100 60 10000"
*
*
* $ redis-cli config get 'm*'
* 1. "masterauth"
* 2. (nil)
Expand Down Expand Up @@ -3940,6 +3940,20 @@ public byte[] aclLog(byte[] options) {
return client.getBinaryBulkReply();
}

@Override
public byte[] aclLoadBinary() {
checkIsInMultiOrPipeline();
client.aclLoad();
return client.getBinaryBulkReply();
}

@Override
public byte[] aclSaveBinary() {
checkIsInMultiOrPipeline();
client.aclSave();
return client.getBinaryBulkReply();
}

@Override
public String clientKill(final byte[] ipPort) {
checkIsInMultiOrPipeline();
Expand Down
58 changes: 35 additions & 23 deletions src/main/java/redis/clients/jedis/Jedis.java
Original file line number Diff line number Diff line change
Expand Up @@ -1523,14 +1523,14 @@ public Long sunionstore(final String dstkey, final String... keys) {
* Return the difference between the Set stored at key1 and all the Sets key2, ..., keyN
* <p>
* <b>Example:</b>
*
*
* <pre>
* key1 = [x, a, b, c]
* key2 = [c]
* key3 = [a, d]
* SDIFF key1,key2,key3 =&gt; [x, b]
* </pre>
*
*
* Non existing keys are considered like empty sets.
* <p>
* <b>Time complexity:</b>
Expand Down Expand Up @@ -1866,65 +1866,65 @@ public List<String> sort(final String key) {
* <b>examples:</b>
* <p>
* Given are the following sets and key/values:
*
*
* <pre>
* x = [1, 2, 3]
* y = [a, b, c]
*
*
* k1 = z
* k2 = y
* k3 = x
*
*
* w1 = 9
* w2 = 8
* w3 = 7
* </pre>
*
*
* Sort Order:
*
*
* <pre>
* sort(x) or sort(x, sp.asc())
* -&gt; [1, 2, 3]
*
*
* sort(x, sp.desc())
* -&gt; [3, 2, 1]
*
*
* sort(y)
* -&gt; [c, a, b]
*
*
* sort(y, sp.alpha())
* -&gt; [a, b, c]
*
*
* sort(y, sp.alpha().desc())
* -&gt; [c, a, b]
* </pre>
*
*
* Limit (e.g. for Pagination):
*
*
* <pre>
* sort(x, sp.limit(0, 2))
* -&gt; [1, 2]
*
*
* sort(y, sp.alpha().desc().limit(1, 2))
* -&gt; [b, a]
* </pre>
*
*
* Sorting by external keys:
*
*
* <pre>
* sort(x, sb.by(w*))
* -&gt; [3, 2, 1]
*
*
* sort(x, sb.by(w*).desc())
* -&gt; [1, 2, 3]
* </pre>
*
*
* Getting external keys:
*
*
* <pre>
* sort(x, sp.by(w*).get(k*))
* -&gt; [x, y, z]
*
*
* sort(x, sp.by(w*).get(#).get(k*))
* -&gt; [3, x, 2, y, 1, z]
* </pre>
Expand Down Expand Up @@ -2866,7 +2866,7 @@ public Long bitpos(final String key, final boolean value, final BitPosParams par
* are reported as a list of key-value pairs.
* <p>
* <b>Example:</b>
*
*
* <pre>
* $ redis-cli config get '*'
* 1. "dbfilename"
Expand All @@ -2881,7 +2881,7 @@ public Long bitpos(final String key, final boolean value, final BitPosParams par
* 10. "everysec"
* 11. "save"
* 12. "3600 1 300 100 60 10000"
*
*
* $ redis-cli config get 'm*'
* 1. "masterauth"
* 2. (nil)
Expand Down Expand Up @@ -3131,7 +3131,7 @@ public Long bitop(final BitOP op, final String destKey, final String... srcKeys)
* 22) "2"
* 23) "quorum"
* 24) "2"
*
*
* </pre>
* @return
*/
Expand Down Expand Up @@ -3901,6 +3901,18 @@ public String aclGenPass() {
return client.getStatusCodeReply();
}

@Override
public String aclLoad() {
client.aclLoad();
sazzad16 marked this conversation as resolved.
Show resolved Hide resolved
return client.getStatusCodeReply();
}

@Override
public String aclSave() {
client.aclSave();
sazzad16 marked this conversation as resolved.
Show resolved Hide resolved
return client.getStatusCodeReply();
}

@Override
public List<Long> bitfield(final String key, final String... arguments) {
checkIsInMultiOrPipeline();
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/redis/clients/jedis/Protocol.java
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ public static enum Keyword {
GETNAME, SETNAME, LIST, MATCH, COUNT, PING, PONG, UNLOAD, REPLACE, KEYS, PAUSE, DOCTOR, BLOCK,
NOACK, STREAMS, KEY, CREATE, MKSTREAM, SETID, DESTROY, DELCONSUMER, MAXLEN, GROUP, ID, IDLE,
TIME, RETRYCOUNT, FORCE, USAGE, SAMPLES, STREAM, GROUPS, CONSUMERS, HELP, FREQ, SETUSER,
GETUSER, DELUSER, WHOAMI, CAT, GENPASS, USERS, LOG;
GETUSER, DELUSER, WHOAMI, CAT, GENPASS, USERS, LOG, SAVE;

/**
* @deprecated This will be private in future. Use {@link #getRaw()}.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,5 +81,7 @@ String migrate(String host, int port, int destinationDB, int timeout, MigratePar

byte[] aclLog(byte[] options);

// TODO: Implements ACL LOAD/SAVE commands
byte[] aclLoadBinary();

byte[] aclSaveBinary();
dengliming marked this conversation as resolved.
Show resolved Hide resolved
}
Original file line number Diff line number Diff line change
Expand Up @@ -82,5 +82,7 @@ String migrate(String host, int port, int destinationDB, int timeout, MigratePar

String aclLog(String options);

// TODO: Implements ACL LOAD/SAVE commands
String aclLoad();

String aclSave();
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import redis.clients.jedis.Jedis;
import redis.clients.jedis.Transaction;
import redis.clients.jedis.exceptions.JedisAccessControlException;
import redis.clients.jedis.exceptions.JedisDataException;
import redis.clients.jedis.tests.utils.RedisVersionUtil;
import redis.clients.jedis.util.SafeEncoder;

Expand Down Expand Up @@ -458,4 +459,27 @@ public void aclBinaryCommandsTest() {
jedis.aclDelUser(USER_ZZZ.getBytes());
}

@Test
public void aclLoadTest() {
try {
jedis.aclLoad();
fail("Should throw a JedisDataException: ERR This Redis instance is not configured to use an ACL file...");
} catch (JedisDataException e) {
assertTrue(e.getMessage().contains("ERR This Redis instance is not configured to use an ACL file."));
}

// TODO test with ACL file
}

@Test
public void aclSaveTest() {
try {
jedis.aclSave();
fail("Should throw a JedisDataException: ERR This Redis instance is not configured to use an ACL file...");
} catch (JedisDataException e) {
assertTrue(e.getMessage().contains("ERR This Redis instance is not configured to use an ACL file."));
}

// TODO test with ACL file
}
}