使用 memcache java 客户端示例
使用 memcache java 客户端示例
原文出处:http://blog.chenlb.com/2008/12/use-memcache-java-client-demo.html
具说大数据量,用这个不错。
memcache java 客户端 api。地址:http://www.danga.com/memcached/apis.bml ,有种客户端,我这使用 Dustin Sallings 版的(已经在 google code 了 http://code.google.com/p/spymemcached/)。
spymemcached 的下载地址:http://spymemcached.googlecode.com/files/memcached-2.2.jar 它依赖 spy.jar,spy.jar的下载地址:http://bleu.west.spy.net/~dustin/repo/spy/jars/spy-2.4.jar
把两个jar放到classpath下,然后写代码试用下:写入
package com.chenlb.use; import java.io.IOException; import java.net.InetSocketAddress; import net.spy.memcached.MemcachedClient; public class MemcacheGetUse { public static void main(String[] args) throws IOException { MemcachedClient c=new MemcachedClient(new InetSocketAddress("172.16.249.220", 11211)); // Retrieve a value (synchronously). Object myObject=c.get("someKey"); System.out.println(myObject); c.shutdown(); } }