ubuntu下memcached安装

 

  1. sudo apt-get install libevent-dev
  2. ./configure
  3. make && make test
  4. sudo make install

测试是否安装成功

  1. 启动memcached 输入 memcached -d -l 192.168.1.150
  2. 下载java客户端xmemcached,运行
MemcachedClientBuilder builder = new XMemcachedClientBuilder(AddrUtil
				.getAddresses("192.168.1.150:11211"));
		MemcachedClient memcachedClient = null;
		try {
			memcachedClient = builder.build();
		} catch (IOException e1) {
			e1.printStackTrace();
		}
		try {
			memcachedClient.set("hello", 0, "Hello,xmemcached");
			String value = memcachedClient.get("hello");
			System.out.println("hello=" + value);
			memcachedClient.delete("hello");
			value = memcachedClient.get("hello");
			System.out.println("hello=" + value);
		} catch (MemcachedException e) {
			System.err.println("MemcachedClient operation fail");
			e.printStackTrace();
		} catch (TimeoutException e) {
			System.err.println("MemcachedClient operation timeout");
			e.printStackTrace();
		} catch (InterruptedException e) {
			// ignore
		}
		try {
			// close memcached client
			memcachedClient.shutdown();
		} catch (IOException e) {
			System.err.println("Shutdown MemcachedClient fail");
			e.printStackTrace();
		}

 运行结果:

 

hello=Hello,xmemcached

hello=null

 

 

 

你可能感兴趣的:(memcached,ubuntu)