Java Code Examples for net.rubyeye.xmemcached.MemcachedClient#incr()

The following examples show how to use net.rubyeye.xmemcached.MemcachedClient#incr() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MemcacheServlet.java    From java-docs-samples with Apache License 2.0 6 votes vote down vote up
@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");
}