Skip to content

Commit

Permalink
more binary method, and better loops after review of the for issue #2170
Browse files Browse the repository at this point in the history
  • Loading branch information
tgrall authored and sazzad16 committed Dec 6, 2020
1 parent 2848ec2 commit 7774f6d
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 18 deletions.
6 changes: 3 additions & 3 deletions src/main/java/redis/clients/jedis/AccessControlLogEntry.java
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,9 @@ public Map<String,Object> getlogEntry() {
* @return A Map with all client info
*/
private Map<String,String> getMapFromRawClientInfo( String clientInfo) {
Map<String,String> clientInfoMap = new LinkedHashMap<>();
List<String> myList = new ArrayList<String>(Arrays.asList(clientInfo.split(" ")));
for (String entry : myList) {
String[] entries = clientInfo.split(" ");
Map<String,String> clientInfoMap = new LinkedHashMap<>(entries.length);
for (String entry : entries) {
String[] kvArray = entry.split("=");
clientInfoMap.put(kvArray[0], (kvArray.length ==2)?kvArray[1]:"" );
}
Expand Down
17 changes: 15 additions & 2 deletions src/main/java/redis/clients/jedis/BinaryJedis.java
Original file line number Diff line number Diff line change
Expand Up @@ -3748,10 +3748,23 @@ public List<byte[]> aclCat(byte[] category) {
}

@Override
public String aclLog(byte[] options) {
public List<byte[]> aclLogBinary() {
checkIsInMultiOrPipeline();
client.aclLog();
return client.getBinaryMultiBulkReply();
}

@Override
public List<byte[]> aclLogBinary(int limit) {
checkIsInMultiOrPipeline();
client.aclLog(limit);
return client.getBinaryMultiBulkReply();
}
@Override
public byte[] aclLog(byte[] options) {
checkIsInMultiOrPipeline();
client.aclLog(options);
return client.getStatusCodeReply();
return client.getBinaryBulkReply();
}

@Override
Expand Down
9 changes: 3 additions & 6 deletions src/main/java/redis/clients/jedis/BuilderFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -528,7 +528,7 @@ public String toString() {
*/
public static final Builder<List<AccessControlLogEntry>> ACCESS_CONTROL_LOG_ENTRY_LIST = new Builder<List<AccessControlLogEntry>>() {

Map<String,Builder> mappingFunctions = createDecoderMap();
private final Map<String,Builder> mappingFunctions = createDecoderMap();

private Map<String, Builder> createDecoderMap() {

Expand All @@ -552,11 +552,8 @@ public List<AccessControlLogEntry> build(Object data) {
}

List<AccessControlLogEntry> list = new ArrayList<>();
List<Object> logEntries = (List<Object>)data;
Iterator<Object> logsArray = logEntries.iterator();

while (logsArray.hasNext()) {
List<Object> logEntryData = (List<Object>) logsArray.next();
List<List<Object>> logEntries = (List<List<Object>>)data;
for (List<Object> logEntryData : logEntries) {
Iterator<Object> logEntryDataIterator = logEntryData.iterator();
AccessControlLogEntry accessControlLogEntry = new AccessControlLogEntry(
createMapFromDecodingFunctions(logEntryDataIterator,mappingFunctions));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,11 @@ public interface AdvancedBinaryJedisCommands {

List<byte[]> aclCat(byte[] category);

String aclLog(byte[] options);
List<byte[]> aclLogBinary();

List<byte[]> aclLogBinary(int limit);

byte[] aclLog(byte[] options);

// TODO: Implements ACL LOAD/SAVE commands
}
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,6 @@ public void aclLogTest() {
assertEquals("command", jedis.aclLog().get(0).getReason());
assertEquals("get", jedis.aclLog().get(0).getObject());


// Capture similar event
jedis.aclLog("RESET");
assertTrue(jedis.aclLog().isEmpty());
Expand All @@ -365,9 +364,6 @@ public void aclLogTest() {
assertEquals(10, jedis.aclLog().get(0).getCount());
assertEquals("get", jedis.aclLog().get(0).getObject());




// Generate another type of error
jedis.auth("antirez", "foo");
try {
Expand All @@ -382,7 +378,6 @@ public void aclLogTest() {
assertEquals("somekeynotallowed", jedis.aclLog().get(0).getObject());
assertEquals("key", jedis.aclLog().get(0).getReason());


jedis.aclLog("RESET");
assertTrue(jedis.aclLog().isEmpty());

Expand Down Expand Up @@ -419,7 +414,10 @@ public void aclLogTest() {
assertEquals("Number of log messages ", 2, jedis.aclLog(2).size());

// Binary tests
jedis.aclLog("RESET".getBytes());
assertEquals("Number of log messages ", 3, jedis.aclLogBinary().size());
assertEquals("Number of log messages ", 2, jedis.aclLogBinary(2).size());
byte[] status = jedis.aclLog("RESET".getBytes());
assertNotNull(status);
assertTrue(jedis.aclLog().isEmpty());

jedis.aclDelUser("antirez");
Expand Down

0 comments on commit 7774f6d

Please sign in to comment.