protected MultiGetResult do_GET_ALL()

in jetcache-support/jetcache-redis/src/main/java/com/alicp/jetcache/redis/RedisCache.java [215:270]


    protected MultiGetResult<K, V> do_GET_ALL(Set<? extends K> keys) {
        if (keys == null || keys.isEmpty()) {
            return new MultiGetResult<K, V>(CacheResultCode.SUCCESS, null, Collections.emptyMap());
        }
        // define the result object early to gain statefulFunction feature.
        Map<K, CacheGetResult<V>> resultMap = new HashMap<>();

        try {
            StringBinaryCommands readCommands = (StringBinaryCommands) readCommands();
            ArrayList<K> keyList = new ArrayList<K>(keys);
            byte[][] newKeys = keyList.stream().map(this::buildKey).toArray(byte[][]::new);

            return this.<StringBinaryCommands, StringPipelineBinaryCommands, MultiGetResult<K, V>>doWithPipeline(readCommands, false, (pipeline) -> {
                List<byte[]> results;
                if (pipeline != null) {
                    List<Response<byte[]>> responseList = new ArrayList<>();

                    for (byte[] newKey : newKeys) {
                        Response<byte[]> response = pipeline.get(newKey);
                        responseList.add(response);
                    }

                    sync(pipeline);

                    results = responseList.stream().map(Response::get).collect(Collectors.toList());
                } else {
                    results = readCommands.mget(newKeys);
                }

                for (int i = 0; i < results.size(); i++) {
                    Object value = results.get(i);
                    K key = keyList.get(i);
                    if (value != null) {
                        CacheValueHolder<V> holder = (CacheValueHolder<V>) valueDecoder.apply((byte[]) value);
                        if (System.currentTimeMillis() >= holder.getExpireTime()) {
                            resultMap.put(key, CacheGetResult.EXPIRED_WITHOUT_MSG);
                        } else {
                            CacheGetResult<V> r = new CacheGetResult<V>(CacheResultCode.SUCCESS, null, holder);
                            resultMap.put(key, r);
                        }
                    } else {
                        resultMap.put(key, CacheGetResult.NOT_EXISTS_WITHOUT_MSG);
                    }
                }

                return new MultiGetResult<K, V>(CacheResultCode.SUCCESS, null, resultMap);
            });
        } catch (Exception ex) {
            logError("GET_ALL", "keys(" + keys.size() + ")", ex);
            if (!resultMap.isEmpty()) {
                return new MultiGetResult<K, V>(CacheResultCode.PART_SUCCESS, ex.toString(), resultMap);
            } else {
                return new MultiGetResult<K, V>(ex);
            }
        }
    }