本文整理汇总了Java中net.rubyeye.xmemcached.MemcachedClient.incr方法的典型用法代码示例。如果您正苦于以下问题:Java MemcachedClient.incr方法的具体用法?Java MemcachedClient.incr怎么用?Java MemcachedClient.incr使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类net.rubyeye.xmemcached.MemcachedClient
的用法示例。
在下文中一共展示了MemcachedClient.incr方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: doGet
import net.rubyeye.xmemcached.MemcachedClient; //导入方法依赖的package包/类
@Override
public void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException,
ServletException {
String addr =
System.getenv().containsKey("GAE_MEMCACHE_HOST")
? System.getenv("GAE_MEMCACHE_HOST") : "localhost";
String port =
System.getenv().containsKey("GAE_MEMCACHE_HOST")
? System.getenv("GAE_MEMCACHE_PORT") : "11211";
String key = "count";
MemcachedClientBuilder builder = new XMemcachedClientBuilder(
AddrUtil.getAddresses(addr + ":" + port));
MemcachedClient client = builder.build();
long count = 0L;
try {
count = client.incr(key, 1L, 0L);
} catch (TimeoutException | InterruptedException | MemcachedException e) {
throw new ServletException("Memcache error", e);
}
resp.setContentType("text/plain");
resp.getWriter().print("Value is " + count + "\n");
}
示例2: incr
import net.rubyeye.xmemcached.MemcachedClient; //导入方法依赖的package包/类
/**
* 原子增加操作
* @param key key 名称
* @param value 值
* @return 自增后的结果
*/
public long incr(String key, long value){
MemcachedClient memcachedClient = null;
try {
memcachedClient = getMemcachedClient();
return memcachedClient.incr(key , value);
} catch (Exception e) {
Logger.error(e);
}
return 0;
}