First of all, let's talk about the main thing we do when we use xmemcached:
When we use xmemcached, we mainly use the Xmemcachedclient object to insert, find and delete the cached data.
However, we do not use the Xmemcachedclient memcachedclient=new xmemcachedclient () method to obtain the Xmemcachedclient object.
Why, because xmemcachedclient this class does not have any parameter settings, such as setting distribution policy, service address, and so on, no, none of these we at least insert when the choice of service node can not,
It is equivalent to a client that provides a way to insert, find, and delete cached data so that we can operate the same as the underlying service. So it involves another class of Xmemcachedclientbuilder,
It manages the corresponding parameters entered by our Java program to generate the Xmemcachedclient object, and then we can use the object to access our cache properly.
So, if we write a simple test class, we can:
If it is used in conjunction with the spring framework, it is also the bean that manages the Xmemcachedclientbuilder, which is configured as follows:
<bean id= "Memcachedclientbuilder" class= "Net.rubyeye.xmemcached.XMemcachedClientBuilder" > <constructor-a Rg> <list>
<!--service node address and port--<bean class= "java.net.InetSocketAddress" > <constructor -arg> <value>127.0.0.1</value> </constructor-arg> <constructor-arg> <value>11211</value> </constructor-arg> </bean>
<bean class= "Java.net.InetSocketAddress" >
<constructor-arg>
<value>127.0.0.1</value>
</constructor-arg>
<constructor-arg>
<value>11210</value>
</constructor-arg>
</bean> </list> </constructor-arg>
<!--weights--<constructor-arg> <list> <value>2</value>
<value>1</value> </list> </constructor-arg>
<!--maximum number of connections--<property name= "connectionpoolsize" value= "/>"
<!--protocol, there are binary, and text, and there's one that doesn't know what the following is text--<property name= "Commandfactory" > <bean class= "n Et.rubyeye.xmemcached.command.TextCommandFactory "></bean> </property>
<!--distribution policy, the default is the remainder hash, the following is a consistent hash (common)--<property name= "Sessionlocator" > <bean class= "ne T.rubyeye.xmemcached.impl.ketamamemcachedsessionlocator "></bean> </property>
<!--set Serialization mode-<property name= "Transcoder" > <bean class= "Net.rubyeye.xmemcached.tra Nscoders. Serializingtranscoder "/> </property> </bean>
<!--definition memcachedclient, through the Memcachedclientbuilder build Method--
<bean id= "memcachedclient" factory-bean= "Memcachedclientbuilder" factory-method= "Build" destroy-method= " Shutdown "/>
Basically these are commonly used parameters, the meaning of the parameters have been noted, but the specific parameters are what to use, different settings what is the difference between:
First, the weights, weights, and the on-service nodes are one by one corresponding. The larger the weight setting, the greater the load, what is the situation, in the bottom is through the corresponding weight to replicate its corresponding node, what means, like I set above, the first node weight of 2, the second is 1,
is equivalent to my three service nodes, and then each time the storage, from the three to choose one, that there are actually two are our actual first service node, so its storage probability is not greater? So the bigger the weight, the bigger the load.
What is the distribution strategy? Is that when we store, specifically put in which node, there is a distribution problem, the distribution strategy is to help us determine the key value you store specifically on which service node is placed.
Xmemcached Learning Note II (simple use)