据我了解,这是该特定客户的限制(顺便说一句,那是什么语言?)。随意在 Github 上为它打开一个问题。
HTTP API 至少可以区分不存在的计数器和值恰好为 0 的计数器。
例如,这是尝试访问现有键(值设置为 0)的结果:
$ curl http://localhost:8098/types/counters/buckets/room_occupancy/datatypes/room-215 -v
> GET /types/counters/buckets/room_occupancy/datatypes/room-215 HTTP/1.1
> Accept: */*
>
< HTTP/1.1 200 OK
< Vary: Accept-Encoding
* Server MochiWeb/1.1 WebMachine/1.10.8 (that head fake, tho) is not blacklisted
< Server: MochiWeb/1.1 WebMachine/1.10.8 (that head fake, tho)
< Date: Thu, 20 Aug 2015 03:38:56 GMT
< Content-Type: application/json
< Content-Length: 28
<
* Connection #0 to host localhost left intact
{"type":"counter","value":0}
这是检索一个不存在的键的值的结果:
curl http://localhost:8098/types/counters/buckets/room_occupancy/datatypes/non-existent-room -v
> GET /types/counters/buckets/room_occupancy/datatypes/non-existent-room HTTP/1.1
> User-Agent: curl/7.37.1
> Host: localhost:8098
> Accept: */*
>
< HTTP/1.1 404 Object Not Found
< Vary: Accept-Encoding
* Server MochiWeb/1.1 WebMachine/1.10.8 (that head fake, tho) is not blacklisted
< Server: MochiWeb/1.1 WebMachine/1.10.8 (that head fake, tho)
< Date: Thu, 20 Aug 2015 03:32:51 GMT
< Content-Type: application/json
< Content-Length: 37
<
{"type":"counter","error":"notfound"}
但是,您可以使用现有客户端执行一种解决方法。
您可以为该计数器发出常规的 Fetch Object 操作(最好将“HEAD only”选项设置为 true)。Riak 计数器(或任何其他数据类型)仍然作为常规对象存在,您可以向它发出 HEAD 请求(与 Fetch Counter 或其他相反),它会按预期返回 404。