欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

spring简单两步完成memcached的集成

程序员文章站 2024-01-09 13:58:52
...
简单两步完成memcached的集成
1、在pom.xml文件中引入memcached的jar包
    <dependency>
        <groupId>memcached_client</groupId>
        <artifactId>java_memcached_client</artifactId>
        <version>3.0.2</version>
    </dependency>

2、在Java类中添加如下代码:
private static MemCachedClient client;

    public static void testMemCached(){
        String[] server = {"127.0.0.1:11211"};
        SockIOPool pool = SockIOPool.getInstance("testService");//testService是poolName
        pool.setServers(server);
        pool.setFailover(true);
        pool.setInitConn(10);
        pool.setMinConn(5);
        pool.setMaxConn(100);
        pool.setMaintSleep(30);
        pool.setNagle(false);
        pool.setSocketTO(3000);
        pool.setBufferSize(1024*1024*10);
        pool.setAliveCheck(true);
        pool.initialize();

        client = new MemCachedClient("testService");
        client.set("key", "value");
        System.out.println(client.get("key"));
    }
相关标签: memcached

上一篇:

下一篇: