Integrate with spring with memcached client xmemcached

Source: Internet
Author: User
Tags memcached

1 Introduction
Xmemcached is a high-performance Java NIO-based memcached client. After three RC versions, the 1.10-final version is officially released.
Xmemcached Features at a glance:
1. High performance
2, support the complete memcached text protocol, the binary Protocol will be implemented in version 1.2.
3. Support JMX, can adjust performance parameters through Mbean, dynamically add/Remove server, view statistics, etc.
4, support client statistics
5, support the dynamic increase or decrease of memcached node.
6, support memcached distribution: Remainder distribution and consistent hash distribution.
7. More performance tuning options.


2 Integration with spring
Xmemcached from 1.1.2, it can be flexibly and conveniently integrated with the spring framework.
2.1 The simplest example
<bean name= "memcachedclient" class= "Net.rubyeye.xmemcached.utils.XMemcachedClientFactoryBean" >
<property name= "Servers" >
<value>host1:port1 host2:port2</value>
</property>
</bean>
You can then use the memcachedclient in the bean.
2.2 A little bit more complicated example
<bean name= "Memcachedclient"
class= "Net.rubyeye.xmemcached.utils.XMemcachedClientFactoryBean" >
<property name= "Servers" >
<value>host1:port1 Host2:port2 host3:port3</value>
</property>
<property name= "Weights" >
<list>
<value>1</value>
<value>2</value>
<value>3</value>
</list>
</property>
<property name= "Sessionlocator" >
<bean class= "Net.rubyeye.xmemcached.impl.KetamaMemcachedSessionLocator" ></bean>
</property>
<property name= "Transcoder" >
<bean class= "Net.rubyeye.xmemcached.transcoders.SerializingTranscoder"/>
</property>
<property name= "Bufferallocator" >
<bean class= "Net.rubyeye.xmemcached.buffer.SimpleBufferAllocator" ></bean>
</property>
</bean>

The meaning of each parameter:

Parameters

Meaning

Servers

Server list, format:ip:port

Weights

Host mapping:host1 corresponds to number 1th, Host2 2nd .

Sessionlocator

Session

dispensers, which have their own, affect distributed

Transcoder

Communication Coding Method

Bufferallocator

Buffer Allocator


Note:

Default standard hash, hash (key) mod server_count (remainder distribution)

Memcachedclientbuilder builder = new Xmemcachedclientbuilder (addrutil.getaddresses ("server1:11211 server2:11211 server3:11211 ")); memcachedclient MC = Builder.build ();




Can be changed to consistent hash (consistent hash):

Memcachedclientbuilder builder = new Xmemcachedclientbuilder (addrutil.getaddresses ("server1:11211 server2:11211 server3:11211 ")); Builder.setsessionlocator (New Ketamamemcachedsessionlocator ()); memcachedclient MC = Builder.build ();

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Integrate with spring with memcached client xmemcached

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.