• Spring 集成 MemCache


    1)xml

    <bean class="com.danga.MemCached.SockIOPool"
            factory-method="getInstance" init-method="initialize" destroy-method="shutDown">
            <constructor-arg>
            <value>someSockIOPool</value>
            </constructor-arg> 
            <property name="servers">
                <list>
                    <value>someIP1:11261</value>
                    <value>someIP2:11261</value>
                </list>
            </property>
    </bean>
    <bean class="com.danga.MemCached.MemCachedClient">
            <!-- 需要与SockIOPool同名,不写时为默认值default ,可自行查看源码 -->
            <constructor-arg>
            <value>someSockIOPool</value>
            </constructor-arg>
    </bean>

    2)java

    @Autowired
    MemCachedClient memCachedClient;
    
    @Test
    public void memcacheTest() {
        memCachedClient.add("kk", "1");
        System.out.println(memCachedClient.get("kk"));
    }

    3)pom.xml

    <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
        <modelVersion>4.0.0</modelVersion>
        <groupId>cn.test</groupId>
        <artifactId>test</artifactId>
        <version>0.0.1-SNAPSHOT</version>
        <name>test</name>
        
        <repositories>
            <repository>
                <id>nexus</id>
                <name>local private nexus</name>
                <url>http://maven.oschina.net/content/groups/public/</url>
            </repository>
        </repositories>
        <dependencies>
            <dependency>
                <groupId>org.slf4j</groupId>
                <artifactId>slf4j-simple</artifactId>
                <version>1.6.4</version>
            </dependency>
            <dependency>
                <groupId>org.slf4j</groupId>
                <artifactId>slf4j-api</artifactId>
                <version>1.6.4</version>
            </dependency>
            <dependency>
                <groupId>commons-pool</groupId>
                <artifactId>commons-pool</artifactId>
                <version>1.5.6</version>
            </dependency>
            <dependency>
                <groupId>com.danga</groupId>
                <artifactId>java-memcached</artifactId>
                <version>2.6.3</version>
            </dependency>
        </dependencies>
            
    </project>

    java-memcached 源码:

    https://github.com/gwhalin/Memcached-Java-Client/

    java-memcached 下载地址:

    https://github.com/gwhalin/Memcached-Java-Client/downloads

  • 相关阅读:
    Spring源码加载BeanDefinition过程
    设计模式之☞委派模式,通俗易懂,一学就会!!!
    SpringMvc 跨域处理
    寻找全排列的下一个数
    使用两个栈实现队列
    无序数组在排序后的最大相邻查
    判断一个数是否是2的幂
    最大公约数
    最小栈的实现
    js 原型与原型链
  • 原文地址:https://www.cnblogs.com/zno2/p/4538737.html
Copyright © 2020-2023  润新知