第 5 章 使用计数器
计数器提供记录对象计数的原子递增和减少操作。
先决条件
- 启动 Data Grid CLI。
- 连接到正在运行的 Data Grid 集群。
5.1. 创建计数器 复制链接链接已复制到粘贴板!
复制链接链接已复制到粘贴板!
使用 Data Grid CLI 创建强大和弱计数器。
流程
- 创建与 Data Grid 的 CLI 连接。
使用适当的参数运行
create counter
命令。创建
my-weak-counter
。[//containers/default]> create counter --concurrency-level=1 --initial-value=5 --storage=PERSISTENT --type=weak my-weak-counter
[//containers/default]> create counter --concurrency-level=1 --initial-value=5 --storage=PERSISTENT --type=weak my-weak-counter
Copy to Clipboard Copied! Toggle word wrap Toggle overflow 创建
my-strong-counter
。[//containers/default]> create counter --initial-value=3 --storage=PERSISTENT --type=strong my-strong-counter
[//containers/default]> create counter --initial-value=3 --storage=PERSISTENT --type=strong my-strong-counter
Copy to Clipboard Copied! Toggle word wrap Toggle overflow
列出可用的计数器。
[//containers/default]> ls counters my-strong-counter my-weak-counter
[//containers/default]> ls counters my-strong-counter my-weak-counter
Copy to Clipboard Copied! Toggle word wrap Toggle overflow 验证计数器配置。
描述
my-weak-counter
。Copy to Clipboard Copied! Toggle word wrap Toggle overflow 描述
my-strong-counter
。Copy to Clipboard Copied! Toggle word wrap Toggle overflow