Este contenido no está disponible en el idioma seleccionado.
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 Copiar enlaceEnlace copiado en el portapapeles!
Create strong and weak counters with the Data Grid CLI.
Procedure
Run
create counterwith the appropriate arguments.Create
my-weak-counter.[//containers/default]> create counter --concurrency-level=1 --initial-value=5 --storage=PERSISTENT --type=weak my-weak-counterCreate
my-strong-counter.[//containers/default]> create counter --initial-value=3 --storage=PERSISTENT --type=strong my-strong-counter
List available counters.
[//containers/default]> ls counters my-strong-counter my-weak-counterVerify counter configurations.
Describe
my-weak-counter.[//containers/default]> describe counters/my-weak-counter { "weak-counter":{ "initial-value":5, "storage":"PERSISTENT", "concurrency-level":1 } }Describe
my-strong-counter.[//containers/default]> describe counters/my-strong-counter { "strong-counter":{ "initial-value":3, "storage":"PERSISTENT", "upper-bound":5 } }
5.2. Adding Deltas to Counters Copiar enlaceEnlace copiado en el portapapeles!
Increment or decrement counters with arbitrary values.
Procedure
Select a counter.
[//containers/default]> counter my-weak-counterList the current count.
[//containers/default/counters/my-weak-counter]> ls 5Increment the counter value by
2.[//containers/default/counters/my-weak-counter]> add --delta=2Decrement the counter value by
-4.[//containers/default/counters/my-weak-counter]> add --delta=-4
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.