I installed a Windows version of the Memcached client locally and added it as a Windows service.
To add a MAVEN package:
<dependency> <groupId>com.google.code.simple-spring-memcached</groupId> <artifa Ctid>xmemcached-provider</artifactid> <scope>runtime</scope> </dependency>
To make a simple testcase:
package com.raycloud.maijia.schedule.utils;import java.io.ioexception;import java.util.concurrent.timeoutexception;import net.rubyeye.xmemcached.memcachedclient;import Net.rubyeye.xmemcached.xmemcachedclient;import net.rubyeye.xmemcached.exception.memcachedexception;import org.junit.Test;public class TestMemcached { @Test public void testit () { try { MemcachedClient Client = new xmemcachedclient ("127.0.0.1", 11556); String testVal = "This is a test demo."; client.set ("Test_key", 10, TestVal); &nbSp; thread.sleep (; ) system.out.println ("=================" + client.get ("Test_key")); thread.sleep (15000); system.out.println ("=================" + client.get ("Test_ Key ")); } catch (ioexception e) { // todo auto-generated catch block e.printstacktrace (); } catch (timeoutexception e) { // todo auto-generated catch block &nbSp; e.printstacktrace (); } catch (interruptedexception e) { // TODO Auto-generated catch block e.printstacktrace (); } catch (memcachedexception e) { // TODO Auto-generated catch block e.printstacktrace (); } } }
Output Result:
13:51:57.904 [xmemcached-reactor-2] debug c.g.c.y.core.impl.abstractsession - read 64 bytes from channel=================this is a test demo.13 : 52:02.906 [xmemcached-reactor-2] debug n.r.xmemcached.impl.memcachedhandler - check session (%s) is alive,send heartbeat13:52:02.907 [Xmemcached-Reactor-2] debug c.g.c.y.core.impl.abstractsession - after encodingversion13:52:02.908 [ Xmemcached-reactor-2] debug n.rubyeye.xmemcached.impl.optimizer - optimieze merge buffer:version13:52:02.908 [xmemcached-reactor-2] debug c.g.c.y.core.impl.abstractsession - send buffers:[ buffer:position=0,limit=9,capacity=9]13:52:02.910 [ Xmemcached-reactor-2] debug c.g.c.y.core.impl.abstractsession - read 16 bytes from channel13:52:07.911 [xmemcached-reactor-2] debug n.r.xmemcached.impl.memcachedhandler - check session (%s) is alive,send heartbeat13:52:07.912 [Xmemcached-Reactor-2] DEBUG c.g.c.y.core.impl.abstractsession - after encodingversion13:52:07.912 [ Xmemcached-reactor-2] debug n.rubyeye.xmemcached.impl.optimizer - optimieze merge buffer:version13:52:07.912 [xmemcached-reactor-2] debug c.g.c.y.core.impl.abstractsession - send buffers:[ buffer:position=0,limit=9,capacity=9]13:52:07.924 [ Xmemcached-reactor-2] debug c.g.c.y.core.impl.abstractsession - read 16 bytes from channel13:52:12.906 [main] DEBUG c.g.c.y.core.impl.AbstractSession - after encodingget test_key13:52:12.907 [xmemcached-reactor-2] debug N.rubyeye.xmemcached.impl.optimizer - optimieze merge buffer:get test_key13:52:12.908 [xmemcached-reactor-2] debug c.g.c.y.core.impl.abstractsession - send buffers:[ buffer:position=0,limit=14,capacity=14]13:52:12.909 [xmemcached-reactor-2] debug c.g.c.y.core.impl.abstractsession - read 5 bytes from channel======== =========null
Spring Configuration:
<bean name= "memcachedclient" class= "Net.rubyeye.xmemcached.utils.XMemcachedClientFactoryBean" destroy-method= " Shutdown "> <property name=" Servers "> <value>${memcached.url}</value> </PR operty> <property name= "Commandfactory" > <bean class= "Net.rubyeye.xmemcached.command.BinaryC Ommandfactory "></bean> </property> </bean>
(not to be continued)
Integration of xmemcached and spring