Mic*_*ick 7 protocol-buffers redis
我使用 Jedis 作为 java 客户端来连接到 Redis 服务器。我还使用协议缓冲区将数据写入 jedis 或 redis 缓存中。但是我没有找到如何将 protobuf 对象写入或设置为 redis 的方法。我是否遗漏了什么或 Jedis 没有提供将 protobuf 对象存储为值的方法?
这是一个迟到的答案......
您可以将 Protobuf 消息序列化为二进制字符串,并使用SET命令将其保存到 Redis 。但是,每当您需要获取 Protobuf 消息时,您都必须取回二进制字符串,并将其反序列化。即使您只想获得一个字段。
另一种解决方案是,您可以使用redis-protobuf模块将 Protobuf 消息保存到 Redis 中。使用此模块,您可以读取或写入 Protobuf 消息。如果您只需要一个字段,则不需要取回整个消息,redis-protobuf只会返回该字段。
免责声明:我是redis-protobuf.