我正在尝试使用 spymemcached-2.8.4 客户端在 memcached 中设置一个非常基本的命中率监视器,但是存储在 memcached 中的值实际上似乎从未增加......这是一个错误还是我错过了什么?
public static void checkHitRate(String clientId) throws FatalException, ForbiddenException {
MemcachedClient memcachedClient;
try {
memcachedClient = new MemcachedClient(new InetSocketAddress("localhost", 11211));
Integer hitRate = (Integer) memcachedClient.get(clientId);
if (hitRate == null) {
memcachedClient.set(clientId, 1800, 1);
} else if (hitRate > 500) {
throw new ForbiddenException("Hit rate too high. Try again later");
} else if (hitRate <= 500) {
memcachedClient.incr(clientId, 1);
}
} catch (IOException e) {
throw new FatalException("Could not read hit rate from Memcached.");
}
}
我知道它在 memcached 中是可能的:
(TELENT 输出)
set clientId_1 0 200 1
1
STORED
incr clientId_1 1
2
get clientId_1
VALUE clientId_1 0 1
2
END