,java,redis"/>

首页 > 解决方案 > 如何在 spring redis executepiplelined as Map 中获取 hgetall 结果

问题描述

有什么办法,我可以在使用spring redis在管道中执行hgetall请求时获取列表?

我在尝试:

RedisCallback action = connection -> {
        evictDataItems.forEach(evictDataItem->connection.hGetAll(evictDataItem.getPrimaryKey()));
        return null;
    };
    List<Map<byte[],byte[]>> list = template.executePipelined(action);

这些 Map 的值需要传递给下一个请求。

但是,executePipelined 本身使用 JDK Serializer 将其转换为字符串。所以我得到了地图。这些字节是我使用多个序列化程序创建的自定义字节。

因此,如果我们对此有任何选择,请告诉我。

标签: javaredis

解决方案


我用了

List<Map<byte[],byte[]>> list = template.executePipelined(action, new BytesRedisSerializer());

public class BytesRedisSerializer implements RedisSerializer {

    @Override
    public byte[] serialize(Object t) throws SerializationException {
        return (byte[]) t;
    }

    @Override
    public Object deserialize(byte[] bytes) throws SerializationException {
        return bytes;
    }

}

推荐阅读