Search in sources :

Example 1 with MapGetAllDecoder

use of org.redisson.connection.decoder.MapGetAllDecoder 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;
}
Also used : ObjectMapDecoder(org.redisson.client.protocol.decoder.ObjectMapDecoder) ListMultiDecoder(org.redisson.client.protocol.decoder.ListMultiDecoder) LongMultiDecoder(org.redisson.client.protocol.decoder.LongMultiDecoder) MapScanCodec(org.redisson.client.codec.MapScanCodec) RFuture(org.redisson.api.RFuture) ScanObjectEntry(org.redisson.client.protocol.decoder.ScanObjectEntry) MapCacheScanResult(org.redisson.client.protocol.decoder.MapCacheScanResult) MapCacheScanResultReplayDecoder(org.redisson.client.protocol.decoder.MapCacheScanResultReplayDecoder) RedisCommand(org.redisson.client.protocol.RedisCommand) MapGetAllDecoder(org.redisson.connection.decoder.MapGetAllDecoder) ArrayList(java.util.ArrayList) List(java.util.List) ObjectListDecoder(org.redisson.client.protocol.decoder.ObjectListDecoder)

Example 2 with MapGetAllDecoder

use of org.redisson.connection.decoder.MapGetAllDecoder in project redisson by redisson.

the class RedissonBuckets method get.

@Override
public <V> Map<String, V> get(String... keys) {
    if (keys.length == 0) {
        return Collections.emptyMap();
    }
    RedisCommand<Map<Object, Object>> command = new RedisCommand<Map<Object, Object>>("MGET", new MapGetAllDecoder(Arrays.<Object>asList(keys), 0), ValueType.OBJECTS);
    RFuture<Map<String, V>> future = commandExecutor.readAsync(keys[0], new DelegateDecoderCodec(codec), command, keys);
    return commandExecutor.get(future);
}
Also used : RedisCommand(org.redisson.client.protocol.RedisCommand) MapGetAllDecoder(org.redisson.connection.decoder.MapGetAllDecoder) DelegateDecoderCodec(org.redisson.client.codec.DelegateDecoderCodec) Map(java.util.Map)

Example 3 with MapGetAllDecoder

use of org.redisson.connection.decoder.MapGetAllDecoder in project redisson by redisson.

the class RedissonGeo method hashAsync.

@Override
public RFuture<Map<V, String>> hashAsync(V... members) {
    List<Object> params = new ArrayList<Object>(members.length + 1);
    params.add(getName());
    params.addAll(Arrays.asList(members));
    RedisCommand<Map<Object, Object>> command = new RedisCommand<Map<Object, Object>>("GEOHASH", new MapGetAllDecoder(params, 1), 2, ValueType.OBJECTS);
    return commandExecutor.readAsync(getName(), new ScoredCodec(codec), command, params.toArray());
}
Also used : ArrayList(java.util.ArrayList) RedisCommand(org.redisson.client.protocol.RedisCommand) ScoredCodec(org.redisson.client.codec.ScoredCodec) MapGetAllDecoder(org.redisson.connection.decoder.MapGetAllDecoder) Map(java.util.Map)

Aggregations

RedisCommand (org.redisson.client.protocol.RedisCommand)3 MapGetAllDecoder (org.redisson.connection.decoder.MapGetAllDecoder)3 ArrayList (java.util.ArrayList)2 Map (java.util.Map)2 List (java.util.List)1 RFuture (org.redisson.api.RFuture)1 DelegateDecoderCodec (org.redisson.client.codec.DelegateDecoderCodec)1 MapScanCodec (org.redisson.client.codec.MapScanCodec)1 ScoredCodec (org.redisson.client.codec.ScoredCodec)1 ListMultiDecoder (org.redisson.client.protocol.decoder.ListMultiDecoder)1 LongMultiDecoder (org.redisson.client.protocol.decoder.LongMultiDecoder)1 MapCacheScanResult (org.redisson.client.protocol.decoder.MapCacheScanResult)1 MapCacheScanResultReplayDecoder (org.redisson.client.protocol.decoder.MapCacheScanResultReplayDecoder)1 ObjectListDecoder (org.redisson.client.protocol.decoder.ObjectListDecoder)1 ObjectMapDecoder (org.redisson.client.protocol.decoder.ObjectMapDecoder)1 ScanObjectEntry (org.redisson.client.protocol.decoder.ScanObjectEntry)1