use of org.redisson.client.protocol.ScoredEntry in project redisson by redisson.
the class CommandAsyncService method handleReference.
private <R, V> void handleReference(RPromise<R> mainPromise, R res) {
if (res instanceof List) {
List<Object> r = (List<Object>) res;
for (int i = 0; i < r.size(); i++) {
if (r.get(i) instanceof RedissonReference) {
try {
r.set(i, redisson != null ? RedissonObjectFactory.fromReference(redisson, (RedissonReference) r.get(i)) : RedissonObjectFactory.fromReference(redissonReactive, (RedissonReference) r.get(i)));
} catch (Exception exception) {
//skip and carry on to next one.
}
} else if (r.get(i) instanceof ScoredEntry && ((ScoredEntry) r.get(i)).getValue() instanceof RedissonReference) {
try {
ScoredEntry<?> se = ((ScoredEntry<?>) r.get(i));
se = new ScoredEntry(se.getScore(), redisson != null ? RedissonObjectFactory.<R>fromReference(redisson, (RedissonReference) se.getValue()) : RedissonObjectFactory.<R>fromReference(redissonReactive, (RedissonReference) se.getValue()));
r.set(i, se);
} catch (Exception exception) {
//skip and carry on to next one.
}
}
}
mainPromise.trySuccess(res);
} else if (res instanceof ListScanResult) {
List<ScanObjectEntry> r = ((ListScanResult) res).getValues();
for (int i = 0; i < r.size(); i++) {
Object obj = r.get(i);
if (!(obj instanceof ScanObjectEntry)) {
break;
}
ScanObjectEntry e = r.get(i);
if (e.getObj() instanceof RedissonReference) {
try {
r.set(i, new ScanObjectEntry(e.getBuf(), redisson != null ? RedissonObjectFactory.<R>fromReference(redisson, (RedissonReference) e.getObj()) : RedissonObjectFactory.<R>fromReference(redissonReactive, (RedissonReference) e.getObj())));
} catch (Exception exception) {
//skip and carry on to next one.
}
} else if (e.getObj() instanceof ScoredEntry && ((ScoredEntry<?>) e.getObj()).getValue() instanceof RedissonReference) {
try {
ScoredEntry<?> se = ((ScoredEntry<?>) e.getObj());
se = new ScoredEntry(se.getScore(), redisson != null ? RedissonObjectFactory.<R>fromReference(redisson, (RedissonReference) se.getValue()) : RedissonObjectFactory.<R>fromReference(redissonReactive, (RedissonReference) se.getValue()));
r.set(i, new ScanObjectEntry(e.getBuf(), se));
} catch (Exception exception) {
//skip and carry on to next one.
}
}
}
mainPromise.trySuccess(res);
} else if (res instanceof MapScanResult) {
Map<ScanObjectEntry, ScanObjectEntry> map = ((MapScanResult) res).getMap();
HashMap<ScanObjectEntry, ScanObjectEntry> toAdd = null;
for (Map.Entry<ScanObjectEntry, ScanObjectEntry> e : map.entrySet()) {
if (e.getValue().getObj() instanceof RedissonReference) {
try {
e.setValue(new ScanObjectEntry(e.getValue().getBuf(), redisson != null ? RedissonObjectFactory.<R>fromReference(redisson, (RedissonReference) e.getValue().getObj()) : RedissonObjectFactory.<R>fromReference(redissonReactive, (RedissonReference) e.getValue().getObj())));
} catch (Exception exception) {
//skip and carry on to next one.
}
}
if (e.getKey().getObj() instanceof RedissonReference) {
if (toAdd == null) {
toAdd = new HashMap<ScanObjectEntry, ScanObjectEntry>();
}
toAdd.put(e.getKey(), e.getValue());
}
}
if (toAdd != null) {
for (Map.Entry<ScanObjectEntry, ScanObjectEntry> e : toAdd.entrySet()) {
try {
map.put(new ScanObjectEntry(e.getValue().getBuf(), (redisson != null ? RedissonObjectFactory.<R>fromReference(redisson, (RedissonReference) e.getKey().getObj()) : RedissonObjectFactory.<R>fromReference(redissonReactive, (RedissonReference) e.getKey().getObj()))), map.remove(e.getKey()));
} catch (Exception exception) {
//skip and carry on to next one.
}
}
}
mainPromise.trySuccess(res);
} else if (res instanceof RedissonReference) {
try {
mainPromise.trySuccess(redisson != null ? RedissonObjectFactory.<R>fromReference(redisson, (RedissonReference) res) : RedissonObjectFactory.<R>fromReference(redissonReactive, (RedissonReference) res));
} catch (Exception exception) {
//fallback
mainPromise.trySuccess(res);
}
} else {
mainPromise.trySuccess(res);
}
}
use of org.redisson.client.protocol.ScoredEntry in project gora by apache.
the class RedisStore method runQuery.
private Collection<K> runQuery(Query<K, T> query) {
Collection<K> range;
if (isNumericKey()) {
RScoredSortedSet<Object> index = redisInstance.getScoredSortedSet(generateIndexKey());
Collection<ScoredEntry<Object>> rangeResponse;
int limit = query.getLimit() > -1 ? (int) query.getLimit() : Integer.MAX_VALUE;
if (query.getStartKey() != null && query.getEndKey() != null) {
rangeResponse = index.entryRange(obtainDoubleValue(query.getStartKey()), true, obtainDoubleValue(query.getEndKey()), true, 0, limit);
} else if (query.getStartKey() != null && query.getEndKey() == null) {
rangeResponse = index.entryRange(obtainDoubleValue(query.getStartKey()), true, Double.MAX_VALUE, true, 0, limit);
} else if (query.getStartKey() == null && query.getEndKey() != null) {
rangeResponse = index.entryRange(Double.MIN_VALUE, true, obtainDoubleValue(query.getEndKey()), true, 0, limit);
} else {
rangeResponse = index.entryRange(Double.MIN_VALUE, true, Double.MAX_VALUE, true, 0, limit);
}
range = new ArrayList<>();
for (ScoredEntry<Object> indexVal : rangeResponse) {
range.add((K) indexVal.getValue());
}
} else {
RLexSortedSet index = redisInstance.getLexSortedSet(generateIndexKey());
Collection<String> rangeResponse;
int limit = query.getLimit() > -1 ? (int) query.getLimit() : Integer.MAX_VALUE;
if (query.getStartKey() != null && query.getEndKey() != null) {
rangeResponse = index.range(query.getStartKey().toString(), true, query.getEndKey().toString(), true, 0, limit);
} else if (query.getStartKey() != null && query.getEndKey() == null) {
rangeResponse = index.rangeTail(query.getStartKey().toString(), true, 0, limit);
} else if (query.getStartKey() == null && query.getEndKey() != null) {
rangeResponse = index.rangeHead(query.getEndKey().toString(), true, 0, limit);
} else {
rangeResponse = index.stream().limit(limit).collect(Collectors.toList());
}
range = new ArrayList<>();
for (String indexVal : rangeResponse) {
range.add((K) indexVal);
}
}
return range;
}
use of org.redisson.client.protocol.ScoredEntry in project redisson by redisson.
the class RedissonObjectBuilder method tryHandleReference0.
private Object tryHandleReference0(Object o, ReferenceType type) throws ReflectiveOperationException {
if (o instanceof RedissonReference) {
return fromReference((RedissonReference) o, type);
} else if (o instanceof ScoredEntry && ((ScoredEntry) o).getValue() instanceof RedissonReference) {
ScoredEntry<?> se = (ScoredEntry<?>) o;
return new ScoredEntry(se.getScore(), fromReference((RedissonReference) se.getValue(), type));
} else if (o instanceof Map.Entry) {
Map.Entry old = (Map.Entry) o;
Object key = tryHandleReference0(old.getKey(), type);
Object value = tryHandleReference0(old.getValue(), type);
if (value != old.getValue() || key != old.getKey()) {
return new AbstractMap.SimpleEntry(key, value);
}
}
return o;
}
Aggregations