那些青春的岁月
学习了memcache,这是个好东西,分享一下自己的小实例,也方便以后查找使用
一、前期准备
1) 下载memcached服务端memcached-1.2.6-win32-bin.zip,地址:http://code.jellycan.com/memcached/
1) 下载memcached服务端memcached-1.2.6-win32-bin.zip,地址:http:
//code.jellycan.com/memcached/
2) 下载java版客户端 java_memcached-release_2.6.1.zip
3) 解压缩memcached-1.2.6-win32-bin.zip到指定目录,例如:D:\memcached-1.2.6-win32 ,
D:\memcached-1.2.6-win32\memcached.exe -d install
D:\memcached\memcached.exe -d start
这样memcache就会作为windows系统服务在每次开机时启动memcache服务。
package com.abin.lee.spring.memcache;
import org.junit.BeforeClass;import org.junit.Test;import org.springframework.context.ApplicationContext;import org.springframework.context.support.ClassPathXmlApplicationContext;
import com.danga.MemCached.MemCachedClient;
public class MemcacheUtilTest { static MemCachedClient memcachedClient; @BeforeClass public static void setUpBeforeClass() throws Exception { ApplicationContext context= new ClassPathXmlApplicationContext("com/abin/lee/spring/memcache/spring-memcache.xml"); memcachedClient= (MemCachedClient)context.getBean("memcachedClient"); }
@Test public void test() { memcachedClient.set("name", "abin"); System.out.println(memcachedClient.get("name")); }}
Copyright @ abin Powered by: .Text and ASP.NET Theme by: .NET Monster