use of org.redisson.client.protocol.RedisCommand in project redisson by redisson.
the class RedissonMapCache method scanIteratorAsync.
public RFuture<MapScanResult<ScanObjectEntry, ScanObjectEntry>> scanIteratorAsync(final String name, InetSocketAddress client, long startPos) {
RedisCommand<MapCacheScanResult<Object, Object>> EVAL_HSCAN = new RedisCommand<MapCacheScanResult<Object, Object>>("EVAL", new ListMultiDecoder(new LongMultiDecoder(), new ObjectMapDecoder(new MapScanCodec(codec)), new ObjectListDecoder(codec), new MapCacheScanResultReplayDecoder()), ValueType.MAP);
RFuture<MapCacheScanResult<ScanObjectEntry, ScanObjectEntry>> f = commandExecutor.evalReadAsync(client, name, codec, EVAL_HSCAN, "local result = {}; " + "local idleKeys = {}; " + "local res = redis.call('hscan', KEYS[1], ARGV[2]); " + "local currentTime = tonumber(ARGV[1]); " + "for i, value in ipairs(res[2]) do " + "if i % 2 == 0 then " + "local key = res[2][i-1]; " + "local expireDate = 92233720368547758; " + "local expireDateScore = redis.call('zscore', KEYS[2], key); " + "if expireDateScore ~= false then " + "expireDate = tonumber(expireDateScore) " + "end; " + "local t, val = struct.unpack('dLc0', value); " + "if t ~= 0 then " + "local expireIdle = redis.call('zscore', KEYS[3], key); " + "if expireIdle ~= false then " + "if tonumber(expireIdle) > currentTime and expireDate > currentTime then " + "table.insert(idleKeys, key); " + "end; " + "expireDate = math.min(expireDate, tonumber(expireIdle)) " + "end; " + "end; " + "if expireDate > currentTime then " + "table.insert(result, key); " + "table.insert(result, val); " + "end; " + "end; " + "end;" + "return {res[1], result, idleKeys};", Arrays.<Object>asList(name, getTimeoutSetName(name), getIdleSetName(name)), System.currentTimeMillis(), startPos);
f.addListener(new FutureListener<MapCacheScanResult<ScanObjectEntry, ScanObjectEntry>>() {
@Override
public void operationComplete(Future<MapCacheScanResult<ScanObjectEntry, ScanObjectEntry>> future) throws Exception {
if (future.isSuccess()) {
MapCacheScanResult<ScanObjectEntry, ScanObjectEntry> res = future.getNow();
if (res.getIdleKeys().isEmpty()) {
return;
}
List<Object> args = new ArrayList<Object>(res.getIdleKeys().size() + 1);
args.add(System.currentTimeMillis());
args.addAll(res.getIdleKeys());
commandExecutor.evalWriteAsync(name, codec, new RedisCommand<Map<Object, Object>>("EVAL", new MapGetAllDecoder(args, 1), 7, ValueType.MAP_KEY, ValueType.MAP_VALUE), // index is the first parameter
"local currentTime = tonumber(table.remove(ARGV, 1)); " + "local map = redis.call('hmget', KEYS[1], unpack(ARGV)); " + "for i = #map, 1, -1 do " + "local value = map[i]; " + "if value ~= false then " + "local key = ARGV[i]; " + "local t, val = struct.unpack('dLc0', value); " + "if t ~= 0 then " + "local expireIdle = redis.call('zscore', KEYS[2], key); " + "if expireIdle ~= false then " + "if tonumber(expireIdle) > currentTime then " + "local value = struct.pack('dLc0', t, string.len(val), val); " + "redis.call('hset', KEYS[1], key, value); " + "redis.call('zadd', KEYS[2], t + currentTime, key); " + "end; " + "end; " + "end; " + "end; " + "end; ", Arrays.<Object>asList(name, getIdleSetName(name)), args.toArray());
}
}
});
return (RFuture<MapScanResult<ScanObjectEntry, ScanObjectEntry>>) (Object) f;
}
use of org.redisson.client.protocol.RedisCommand in project redisson by redisson.
the class RedissonBuckets method getAsync.
@Override
public <V> RFuture<Map<String, V>> getAsync(String... keys) {
if (keys.length == 0) {
return RedissonPromise.newSucceededFuture(Collections.emptyMap());
}
Codec commandCodec = new CompositeCodec(StringCodec.INSTANCE, codec, codec);
RedisCommand<Map<Object, Object>> command = new RedisCommand<Map<Object, Object>>("MGET", new MapGetAllDecoder(Arrays.<Object>asList(keys), 0));
return commandExecutor.readBatchedAsync(commandCodec, command, new SlotCallback<Map<Object, Object>, Map<String, V>>() {
final Map<String, V> results = new ConcurrentHashMap<>();
@Override
public void onSlotResult(Map<Object, Object> result) {
for (Map.Entry<Object, Object> entry : result.entrySet()) {
if (entry.getKey() != null && entry.getValue() != null) {
results.put((String) entry.getKey(), (V) entry.getValue());
}
}
}
@Override
public Map<String, V> onFinish() {
return results;
}
@Override
public RedisCommand<Map<Object, Object>> createCommand(List<String> keys) {
return new RedisCommand<>("MGET", new BucketsDecoder(keys));
}
}, keys);
}
use of org.redisson.client.protocol.RedisCommand in project redisson by redisson.
the class RedissonGeo method storeSortedSearchToAsync.
@Override
public RFuture<Long> storeSortedSearchToAsync(String destName, GeoSearchArgs args) {
GeoSearchNode node = (GeoSearchNode) args;
Map<GeoSearchNode.Params, Object> params = node.getParams();
List<Object> commandParams = new ArrayList<>();
if (params.get(GeoSearchNode.Params.HEIGHT) != null) {
commandParams.add(destName);
}
commandParams.add(getRawName());
RedisCommand command = null;
if (params.get(GeoSearchNode.Params.LATITUDE) != null && params.get(GeoSearchNode.Params.LONGITUDE) != null) {
command = RedisCommands.GEORADIUS_STORE;
if (params.get(GeoSearchNode.Params.HEIGHT) != null) {
command = RedisCommands.GEOSEARCHSTORE_STORE;
commandParams.add("FROMLONLAT");
}
commandParams.add(convert((double) params.get(GeoSearchNode.Params.LONGITUDE)));
commandParams.add(convert((double) params.get(GeoSearchNode.Params.LATITUDE)));
}
if (params.get(GeoSearchNode.Params.MEMBER) != null) {
command = RedisCommands.GEORADIUSBYMEMBER_STORE;
if (params.get(GeoSearchNode.Params.HEIGHT) != null) {
command = RedisCommands.GEOSEARCHSTORE_STORE;
commandParams.add("FROMMEMBER");
}
commandParams.add(encode(params.get(GeoSearchNode.Params.MEMBER)));
}
if (params.get(GeoSearchNode.Params.RADIUS) != null && params.get(GeoSearchNode.Params.UNIT) != null) {
commandParams.add(params.get(GeoSearchNode.Params.RADIUS));
commandParams.add(params.get(GeoSearchNode.Params.UNIT));
}
if (params.get(GeoSearchNode.Params.HEIGHT) != null && params.get(GeoSearchNode.Params.UNIT) != null) {
commandParams.add("BYBOX");
commandParams.add(params.get(GeoSearchNode.Params.WIDTH));
commandParams.add(params.get(GeoSearchNode.Params.HEIGHT));
commandParams.add(params.get(GeoSearchNode.Params.UNIT));
if (params.get(GeoSearchNode.Params.ORDER) != null) {
commandParams.add(params.get(GeoSearchNode.Params.ORDER));
}
}
if (params.get(GeoSearchNode.Params.COUNT) != null) {
commandParams.add("COUNT");
commandParams.add(params.get(GeoSearchNode.Params.COUNT));
if (params.get(GeoSearchNode.Params.COUNT_ANY) != null) {
commandParams.add("ANY");
}
}
if (params.get(GeoSearchNode.Params.HEIGHT) == null && params.get(GeoSearchNode.Params.ORDER) != null) {
commandParams.add(params.get(GeoSearchNode.Params.ORDER));
}
commandParams.add("STOREDIST");
if (params.get(GeoSearchNode.Params.HEIGHT) == null) {
commandParams.add(destName);
}
return commandExecutor.writeAsync(getRawName(), LongCodec.INSTANCE, command, commandParams.toArray());
}
use of org.redisson.client.protocol.RedisCommand in project redisson by redisson.
the class RedissonGeo method posAsync.
@Override
public RFuture<Map<V, GeoPosition>> posAsync(V... members) {
List<Object> params = new ArrayList<Object>(members.length + 1);
params.add(getRawName());
for (Object member : members) {
params.add(encode(member));
}
MultiDecoder<Map<Object, Object>> decoder = new ListMultiDecoder2(new GeoPositionMapDecoder((List<Object>) Arrays.asList(members)), new GeoPositionDecoder());
RedisCommand<Map<Object, Object>> command = new RedisCommand<Map<Object, Object>>("GEOPOS", decoder);
return commandExecutor.readAsync(getRawName(), StringCodec.INSTANCE, command, params.toArray());
}
use of org.redisson.client.protocol.RedisCommand in project redisson by redisson.
the class RedissonGeo method searchWithPositionAsync.
@Override
public RFuture<Map<V, GeoPosition>> searchWithPositionAsync(GeoSearchArgs args) {
GeoSearchNode node = (GeoSearchNode) args;
Map<GeoSearchNode.Params, Object> params = node.getParams();
List<Object> commandParams = new ArrayList<>();
commandParams.add(getRawName());
RedisCommand command = null;
if (params.get(GeoSearchNode.Params.LATITUDE) != null && params.get(GeoSearchNode.Params.LONGITUDE) != null) {
command = GEORADIUS_RO_POS;
if (params.get(GeoSearchNode.Params.HEIGHT) != null) {
command = GEOSEARCH_POS;
commandParams.add("FROMLONLAT");
}
commandParams.add(convert((double) params.get(GeoSearchNode.Params.LONGITUDE)));
commandParams.add(convert((double) params.get(GeoSearchNode.Params.LATITUDE)));
}
if (params.get(GeoSearchNode.Params.MEMBER) != null) {
command = GEORADIUSBYMEMBER_RO_POS;
if (params.get(GeoSearchNode.Params.HEIGHT) != null) {
command = GEOSEARCH_POS;
commandParams.add("FROMMEMBER");
}
commandParams.add(encode(params.get(GeoSearchNode.Params.MEMBER)));
}
if (params.get(GeoSearchNode.Params.RADIUS) != null && params.get(GeoSearchNode.Params.UNIT) != null) {
commandParams.add(params.get(GeoSearchNode.Params.RADIUS));
commandParams.add(params.get(GeoSearchNode.Params.UNIT));
}
if (params.get(GeoSearchNode.Params.HEIGHT) != null && params.get(GeoSearchNode.Params.UNIT) != null) {
commandParams.add("BYBOX");
commandParams.add(params.get(GeoSearchNode.Params.WIDTH));
commandParams.add(params.get(GeoSearchNode.Params.HEIGHT));
commandParams.add(params.get(GeoSearchNode.Params.UNIT));
if (params.get(GeoSearchNode.Params.ORDER) != null) {
commandParams.add(params.get(GeoSearchNode.Params.ORDER));
}
}
if (params.get(GeoSearchNode.Params.HEIGHT) == null) {
commandParams.add("WITHCOORD");
}
if (params.get(GeoSearchNode.Params.COUNT) != null) {
commandParams.add("COUNT");
commandParams.add(params.get(GeoSearchNode.Params.COUNT));
if (params.get(GeoSearchNode.Params.COUNT_ANY) != null) {
commandParams.add("ANY");
}
}
if (params.get(GeoSearchNode.Params.HEIGHT) == null && params.get(GeoSearchNode.Params.ORDER) != null) {
commandParams.add(params.get(GeoSearchNode.Params.ORDER));
}
if (params.get(GeoSearchNode.Params.HEIGHT) != null) {
commandParams.add("WITHCOORD");
}
return commandExecutor.readAsync(getRawName(), codec, command, commandParams.toArray());
}
Aggregations