2.2. 创建和管理计数器
通过 REST API 创建、删除和修改计数器。
2.2.1. 创建计数器 复制链接链接已复制到粘贴板!
使用在有效负载中包含配置的 POST 请求创建计数器。
POST /rest/v2/counters/{counterName}
POST /rest/v2/counters/{counterName}
Weak Counter 示例
Strong Counter 示例
2.2.2. 删除计数器 复制链接链接已复制到粘贴板!
使用 DELETE 请求删除特定计数器。
DELETE /rest/v2/counters/{counterName}
DELETE /rest/v2/counters/{counterName}
2.2.3. 检索计数器配置 复制链接链接已复制到粘贴板!
检索具有 GET 请求的特定计数器的配置。
GET /rest/v2/counters/{counterName}/config
GET /rest/v2/counters/{counterName}/config
Data Grid 以 JSON 格式使用计数器配置响应。
2.2.4. 获取计数器值 复制链接链接已复制到粘贴板!
使用 GET 请求检索计数器值。
GET /rest/v2/counters/{counterName}
GET /rest/v2/counters/{counterName}
| 标头 | 必需/可选 | 参数 |
|---|---|---|
| 可选 | 返回内容所需的格式。支持的格式为 application/json 和 text/plain。如果未提供标头,则假定 JSON。 |
2.2.5. 重置计数 复制链接链接已复制到粘贴板!
在没有 POST 请求和 ?action=reset 参数的情况下恢复计数器的初始值。
POST /rest/v2/counters/{counterName}?action=reset
POST /rest/v2/counters/{counterName}?action=reset
如果操作成功完成,服务会返回 204 (不内容)
2.2.6. 增加计数器 复制链接链接已复制到粘贴板!
使用 POST 请求' 和 ?action=increment 参数递增计数器值。
POST /rest/v2/counters/{counterName}?action=increment
POST /rest/v2/counters/{counterName}?action=increment
WEAK 计数器永远不会在操作后响应并返回 204 (不内容)
STRONG 计数器返回 200 (OK),以及每个操作后的当前值。
2.2.7. 将 Deltas 添加到计数器 复制链接链接已复制到粘贴板!
使用包含 ?action=add 和 delta 参数的 POST 请求向计数器添加任意值。
POST /rest/v2/counters/{counterName}?action=add&delta={delta}
POST /rest/v2/counters/{counterName}?action=add&delta={delta}
WEAK 计数器永远不会在操作后响应并返回 204 (不内容)
STRONG 计数器返回 200 (OK),以及每个操作后的当前值。
2.2.8. 缩减计数器值 复制链接链接已复制到粘贴板!
使用 POST 请求和 ?action=decrement 参数减少计数器值。
POST /rest/v2/counters/{counterName}?action=decrement
POST /rest/v2/counters/{counterName}?action=decrement
WEAK 计数器永远不会在操作后响应并返回 204 (不内容)
STRONG 计数器返回 200 (OK),以及每个操作后的当前值。
2.2.9. 在 Strong Counters 上执行 compareAndSet 操作 复制链接链接已复制到粘贴板!
原子为具有 GET 请求和 compareAndSet 参数的强计数器设置值。
POST /rest/v2/counters/{counterName}?action=compareAndSet&expect={expect}&update={update}
POST /rest/v2/counters/{counterName}?action=compareAndSet&expect={expect}&update={update}
如果当前值为 {expect},则以原子方式将值设为 {update}。如果操作成功,Data Grid 返回 true。
2.2.10. 在 Strong Counters 上执行 compareAndSwap 操作 复制链接链接已复制到粘贴板!
atomic 为强计数器设置值与 GET 请求,以及 compareAndSwap 参数。
POST /rest/v2/counters/{counterName}?action=compareAndSwap&expect={expect}&update={update}
POST /rest/v2/counters/{counterName}?action=compareAndSwap&expect={expect}&update={update}
如果当前值为 {expect},则以原子方式将值设为 {update}。如果操作成功,Data Grid 会返回有效负载中前面的值。
2.2.11. 列出计数器 复制链接链接已复制到粘贴板!
检索具有 GET 请求的 Data Grid 集群中的计数器列表。
GET /rest/v2/counters/
GET /rest/v2/counters/