第 6 章 使用 Protobuf Metadata 查询缓存
Data Grid 支持使用 Protocol Buffers (Protobuf)在缓存中构建数据,以便您可以查询它。
先决条件
- 启动 Data Grid CLI。
- 连接到正在运行的 Data Grid 集群。
6.1. 配置介质类型 复制链接链接已复制到粘贴板!
复制链接链接已复制到粘贴板!
使用不同介质类型对缓存条目进行编码,以最适合您的要求的格式存储数据。
例如,以下步骤演示了如何配置 application/x-protostream 介质类型。
流程
创建一个 Data Grid 配置文件来添加名为
qcache的分布式缓存并配置介质类型,例如:<infinispan> <cache-container> <distributed-cache name="qcache"> <encoding> <key media-type="application/x-protostream"/> <value media-type="application/x-protostream"/> </encoding> </distributed-cache> </cache-container> </infinispan>使用
--file=选项,从pcache.xml创建qcache。[//containers/default]> create cache --file=pcache.xml pcache验证
pcache。[//containers/default]> ls caches pcache ___protobuf_metadata [//containers/default]> describe caches/pcache { "distributed-cache" : { "mode" : "SYNC", "encoding" : { "key" : { "media-type" : "application/x-protostream" }, "value" : { "media-type" : "application/x-protostream" } }, "transaction" : { "mode" : "NONE" } } }向
pcache添加一个条目并检查编码。[//containers/default]> put --cache=pcache good morning [//containers/default]> cd caches/pcache [//containers/default/caches/pcache]> get good { "_type" : "string", "_value" : "morning" }