Search in sources :

Example 1 with BucketsDecoder

use of org.redisson.connection.decoder.BucketsDecoder 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);
}
Also used : CompositeCodec(org.redisson.codec.CompositeCodec) Codec(org.redisson.client.codec.Codec) StringCodec(org.redisson.client.codec.StringCodec) CompositeCodec(org.redisson.codec.CompositeCodec) RedisCommand(org.redisson.client.protocol.RedisCommand) MapGetAllDecoder(org.redisson.connection.decoder.MapGetAllDecoder) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) BucketsDecoder(org.redisson.connection.decoder.BucketsDecoder)

Aggregations

ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 Codec (org.redisson.client.codec.Codec)1 StringCodec (org.redisson.client.codec.StringCodec)1 RedisCommand (org.redisson.client.protocol.RedisCommand)1 CompositeCodec (org.redisson.codec.CompositeCodec)1 BucketsDecoder (org.redisson.connection.decoder.BucketsDecoder)1 MapGetAllDecoder (org.redisson.connection.decoder.MapGetAllDecoder)1