検索

6.3. Protobuf スキーマを使用したキャッシュのクエリー

download PDF

Data Grid は、JSON を Protobuf に自動的に変換するため、キャッシュエントリーを JSON 形式で読み書きし、Protobuf スキーマを使用してクエリーを実行できます。

たとえば、次の JSON ドキュメントについて考えてみます。

lukecage.json

{
  "_type":"org.infinispan.rest.search.entity.Person",
  "id":2,
  "name":"Luke",
  "surname":"Cage",
  "gender":"MALE",
  "address":{"street":"38th St","postCode":"NY 11221"},
  "phoneNumbers":[{"number":4444},{"number":5555}]
}

jessicajones.json

{
  "_type":"org.infinispan.rest.search.entity.Person",
  "id":1,
  "name":"Jessica",
  "surname":"Jones",
  "gender":"FEMALE",
  "address":{"street":"46th St","postCode":"NY 10036"},
  "phoneNumbers":[{"number":1111},{"number":2222},{"number":3333}]
}

matthewmurdock.json

{
  "_type":"org.infinispan.rest.search.entity.Person",
  "id":3,
  "name":"Matthew",
  "surname":"Murdock",
  "gender":"MALE",
  "address":{"street":"57th St","postCode":"NY 10019"},
  "phoneNumbers":[]
}

前述の各 JSON ドキュメントには次が含まれます。

  • JSON ドキュメントが対応する Protobuf メッセージを識別する _type フィールド。
  • person.proto スキーマのデータ型に対応するいくつかのフィールド。

手順

  1. pcache キャッシュに移動します。

    [//containers/default/caches]> cd pcache
  2. 各 JSON ドキュメントをエントリーとしてキャッシュに追加します。次に例を示します。

    [//containers/default/caches/pcache]> put --encoding=application/json --file=jessicajones.json jessicajones
    [//containers/default/caches/pcache]> put --encoding=application/json --file=matthewmurdock.json matthewmurdock
    [//containers/default/caches/pcache]> put --encoding=application/json --file=lukecage.json lukecage
  3. エントリーが存在することを確認します。

    [//containers/default/caches/pcache]> ls
    lukecage
    matthewmurdock
    jessicajones
  4. キャッシュをクエリーして、性別データ型が MALE である Protobuf Person エンティティーからエントリーを返します。

    [//containers/default/caches/pcache]> query "from org.infinispan.rest.search.entity.Person p where p.gender = 'MALE'"
    {
      "total_results" : 2,
      "hits" : [ {
        "hit" : {
          "_type" : "org.infinispan.rest.search.entity.Person",
          "id" : 2,
          "name" : "Luke",
          "surname" : "Cage",
          "gender" : "MALE",
          "address" : {
            "street" : "38th St",
            "postCode" : "NY 11221"
          },
          "phoneNumbers" : [ {
            "number" : "4444"
          }, {
            "number" : "5555"
          } ]
        }
      }, {
        "hit" : {
          "_type" : "org.infinispan.rest.search.entity.Person",
          "id" : 3,
          "name" : "Matthew",
          "surname" : "Murdock",
          "gender" : "MALE",
          "address" : {
            "street" : "57th St",
            "postCode" : "NY 10019"
          }
        }
      } ]
    }
Red Hat logoGithubRedditYoutubeTwitter

詳細情報

試用、購入および販売

コミュニティー

Red Hat ドキュメントについて

Red Hat をお使いのお客様が、信頼できるコンテンツが含まれている製品やサービスを活用することで、イノベーションを行い、目標を達成できるようにします。

多様性を受け入れるオープンソースの強化

Red Hat では、コード、ドキュメント、Web プロパティーにおける配慮に欠ける用語の置き換えに取り組んでいます。このような変更は、段階的に実施される予定です。詳細情報: Red Hat ブログ.

会社概要

Red Hat は、企業がコアとなるデータセンターからネットワークエッジに至るまで、各種プラットフォームや環境全体で作業を簡素化できるように、強化されたソリューションを提供しています。

© 2024 Red Hat, Inc.