博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
spy memcached spring demo
阅读量:4658 次
发布时间:2019-06-09

本文共 3459 字,大约阅读时间需要 11 分钟。

spring 配置文件

<?xml version="1.0" encoding="UTF-8"?>

<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context"
xmlns:p="http://www.springframework.org/schema/p" xmlns:mvc="http://www.springframework.org/schema/mvc"
xmlns:tx="http://www.springframework.org/schema/tx" xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:task="http://www.springframework.org/schema/task"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd 
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd 
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd 
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd 
http://www.springframework.org/schema/task http://www.springframework.org/schema/task/spring-task-3.0.xsd">
<bean id="memcachedClient" class="net.spy.memcached.spring.MemcachedClientFactoryBean"> 
<property name="servers" value="127.0.0.1:11211"/> 
<property name="protocol" value="BINARY"/> 
<property name="transcoder"> 
<bean class="net.spy.memcached.transcoders.SerializingTranscoder"> 
<property name="compressionThreshold" value="1024"/> 
</bean> 
</property> 
<property name="opTimeout" value="1000"/> 
<property name="timeoutExceptionThreshold" value="1998"/> 
<!-- <property name="hashAlg" value="KETAMA_HASH"/> --> 
<property name="locatorType" value="CONSISTENT"/> 
<property name="failureMode" value="Redistribute"/> 
<property name="useNagleAlgorithm" value="false"/> 
</bean> 
</beans>

 

测试类

import org.springframework.context.ApplicationContext;

import org.springframework.context.support.ClassPathXmlApplicationContext;
import net.spy.memcached.MemcachedClient;

public class MemcachedTest {
public static void main(String[] args) {
MemcachedClient cachedClient;
ApplicationContext context = new ClassPathXmlApplicationContext("classpath:/applicationContext.xml");
cachedClient = (MemcachedClient)context.getBean("memcachedClient");
cachedClient.set("user", 200, "haha");//save user
System.out.println(cachedClient.get("user"));//haha
System.out.println(cachedClient.get("user1"));//null
}
}

需要的jar包,下面有些jar包非必须,部分未用到

spymemcached-2.10.1.jar

commons-beanutils-1.8.3.jar

commons-beanutils-bean-collections-1.8.3.jar
commons-beanutils-core-1.8.3.jar
commons-codec-1.4.jar
commons-collections-3.2.1.jar
commons-io-1.3.2.jar
commons-lang-2.6.jar
commons-logging-1.1.1.jar
log4j.jar
org.springframework.aop-3.0.5.RELEASE.jar
org.springframework.asm-3.0.5.RELEASE.jar
org.springframework.aspects-3.0.5.RELEASE.jar
org.springframework.beans-3.0.5.RELEASE.jar
org.springframework.context-3.0.5.RELEASE.jar
org.springframework.context.support-3.0.5.RELEASE.jar
org.springframework.core-3.0.5.RELEASE.jar
org.springframework.expression-3.0.5.RELEASE.jar
org.springframework.jdbc-3.0.5.RELEASE.jar
org.springframework.transaction-3.0.5.RELEASE.jar
org.springframework.web-3.0.5.RELEASE.jar
org.springframework.web.servlet-3.0.5.RELEASE.jar

 

说明:对于java使用memcached,需下载客户端

spymemcached客户端API:spymemcached client 

网址:http://code.google.com/p/spymemcached/ 

除了spy外,还有memcached client for java客户端

memcached client for java客户端API:memcached client for java 

网址:http://www.whalin.com/memcached 

转载于:https://www.cnblogs.com/zerojevery/p/3848191.html

你可能感兴趣的文章
JS向数组中添加/删除元素
查看>>
House Robber
查看>>
Best Time to Buy and Sell Stock II
查看>>
函数参数按值传递
查看>>
前端微应用:前端大应用拆分为多个小应用(?前端 nginx?)
查看>>
Codeforces Round #574 (Div. 2)
查看>>
洛谷上传数据指南
查看>>
搜索进阶课件,视频,代码(状态压缩搜索,折半搜索,dfs,bfs总结)
查看>>
第一类和第二类Stirling数
查看>>
造题目数据的觅食指南
查看>>
银联高校极客挑战赛 初赛 第一场
查看>>
2019银联高校极客挑战赛 复赛
查看>>
银联高校极客挑战赛 初赛 第二场
查看>>
windows更改文件打开方式
查看>>
windows10 注销 锁定
查看>>
下载文件的文件名之思考
查看>>
微信分享链接时怎样才能带上带缩略图和简介
查看>>
2019 年百度之星·程序设计大赛 - 复赛
查看>>
添加其它邮箱
查看>>
Fiji-imageJ 无法打开
查看>>