java - 如何在 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 将其转换为字符串。所以我得到了地图。这些字节是我使用多个序列化程序创建的自定义字节。
因此,如果我们对此有任何选择,请告诉我。
解决方案
我用了
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;
}
}
推荐阅读
- ios - 无法将 Flurry 添加到我的 Swift 项目中
- php - 在 Woocommerce 单品标题后添加特定产品属性
- windows - Powershell Jobs - 在另一个并行作业中监控正在运行的作业
- ruby-on-rails - Rails 应用程序中的回滚事务错误
- visual-studio-2017 - 在项目创建或连接服务中添加身份验证
- mongodb - 更改 ECS Instance 上 mongodb 的默认端口
- r - 创建一个将其参数传递给 Surv 函数(或任何其他函数)的函数
- python - 如何在列表中插入条件语句?
- java - Spring Integration:文件读取拆分和消息过滤
- php - 类范围内可访问的静态数组,试图推送到它,但总是返回空