Dieser Inhalt ist in der von Ihnen ausgewählten Sprache nicht verfügbar.

Chapter 5. Working with Counters


Counters provide atomic increment and decrement operations that record the count of objects.

Prerequisites

  • Start the Data Grid CLI.
  • Connect to a running Data Grid cluster.

5.1. Creating Counters

Create strong and weak counters with the Data Grid CLI.

Procedure

  1. Create a CLI connection to Data Grid.
  2. Run the create counter command with the appropriate arguments.

    1. Create my-weak-counter.

      [//containers/default]> create counter --concurrency-level=1 --initial-value=5 --storage=PERSISTENT --type=weak my-weak-counter
      Copy to Clipboard Toggle word wrap
    2. Create my-strong-counter.

      [//containers/default]> create counter --initial-value=3 --storage=PERSISTENT --type=strong my-strong-counter
      Copy to Clipboard Toggle word wrap
  3. List available counters.

    [//containers/default]> ls counters
    my-strong-counter
    my-weak-counter
    Copy to Clipboard Toggle word wrap
  4. Verify counter configurations.

    1. Describe my-weak-counter.

      [//containers/default]> describe counters/my-weak-counter
      
      {
          "weak-counter":{
              "initial-value":5,
              "storage":"PERSISTENT",
              "concurrency-level":1
          }
      }
      Copy to Clipboard Toggle word wrap
    2. Describe my-strong-counter.

      [//containers/default]> describe counters/my-strong-counter
      
      {
          "strong-counter":{
              "initial-value":3,
              "storage":"PERSISTENT",
              "upper-bound":5
          }
      }
      Copy to Clipboard Toggle word wrap

5.2. Adding Deltas to Counters

Increment or decrement counters with arbitrary values.

Procedure

  1. Select a counter.

    [//containers/default]> counter my-weak-counter
    Copy to Clipboard Toggle word wrap
  2. List the current count.

    [//containers/default/counters/my-weak-counter]> ls
    5
    Copy to Clipboard Toggle word wrap
  3. Increment the counter value by 2.

    [//containers/default/counters/my-weak-counter]> add --delta=2
    Copy to Clipboard Toggle word wrap
  4. Decrement the counter value by -4.

    [//containers/default/counters/my-weak-counter]> add --delta=-4
    Copy to Clipboard Toggle word wrap
Note

Strong counters return values after the operation is applied. Use --quiet=true to hide the return value.

For example, my-strong-counter]> add --delta=3 --quiet=true.

Weak counters return empty responses.

Nach oben
Red Hat logoGithubredditYoutubeTwitter

Lernen

Testen, kaufen und verkaufen

Communitys

Über Red Hat Dokumentation

Wir helfen Red Hat Benutzern, mit unseren Produkten und Diensten innovativ zu sein und ihre Ziele zu erreichen – mit Inhalten, denen sie vertrauen können. Entdecken Sie unsere neuesten Updates.

Mehr Inklusion in Open Source

Red Hat hat sich verpflichtet, problematische Sprache in unserem Code, unserer Dokumentation und unseren Web-Eigenschaften zu ersetzen. Weitere Einzelheiten finden Sie in Red Hat Blog.

Über Red Hat

Wir liefern gehärtete Lösungen, die es Unternehmen leichter machen, plattform- und umgebungsübergreifend zu arbeiten, vom zentralen Rechenzentrum bis zum Netzwerkrand.

Theme

© 2025 Red Hat