Skip to content

Commit

Permalink
Handle nil from mget
Browse files Browse the repository at this point in the history
  • Loading branch information
utk4rsh-fk committed Apr 6, 2020
1 parent 3ef781d commit a4d8d1b
Showing 1 changed file with 7 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -154,12 +154,16 @@ private List<SchedulerEntry> getSchedulerPayloadValues(int partitionNum, Collect
return schedulerDataList;
try {
jedis = _getInstance(partitionNum);
String[] keys = resultSet.toArray(new String[resultSet.size()]);
//https://stackoverflow.com/questions/174093/toarraynew-myclass0-or-toarraynew-myclassmylist-size
String[] keys = resultSet.toArray(new String[0]);
List<String> schedulerValues = jedis.mget(keys);
Iterator<String> keyIterator = resultSet.iterator();
Iterator<String> valueIterator = schedulerValues.iterator();
while (keyIterator.hasNext() && valueIterator.hasNext()) {
schedulerDataList.add(new DefaultSchedulerEntry(keyIterator.next(), valueIterator.next()));
String key = keyIterator.next();
String value = valueIterator.next();
value = "nil".equalsIgnoreCase(value) ? key : value;
schedulerDataList.add(new DefaultSchedulerEntry(key, value));
}
} catch (Exception ex) {
log.error("Exception occurred for -" + "mget payload for Partition " + partitionNum + "-" + ex.getMessage());
Expand Down Expand Up @@ -196,7 +200,7 @@ private String getKey(long time, int partitionNum) {
return prefix + convertNumToString(time) + DELIMITER + convertNumToString(partitionNum);
}

private String getPayloadKey(String rawKey){
private String getPayloadKey(String rawKey) {
String prefix = keyPrefix != null && !keyPrefix.equals("") ? keyPrefix + DELIMITER : "";
return prefix + rawKey;
}
Expand Down

3 comments on commit a4d8d1b

@kingster
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@utk4rsh
Copy link
Collaborator

@utk4rsh utk4rsh commented on a4d8d1b Apr 7, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I checked few sample code with tests as contains "nil", but this looks correct from Jedis. I could be wrong, have to test it out.

@utk4rsh
Copy link
Collaborator

@utk4rsh utk4rsh commented on a4d8d1b Apr 7, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It should return null as you pointed out. redis/jedis#976

Please sign in to comment.