forked from killme2008/xmemcached
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathREADME
129 lines (92 loc) · 4.01 KB
/
README
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
=======================Introduction==========================
xmemcached
XMemcached is a high performance, easy to use blocking multithreaded memcached client in java.
It's nio based and was carefully tuned to get top performance.
homepage: http://code.google.com/p/xmemcached/
downloads; http://code.google.com/p/xmemcached/downloads/list
wiki : http://code.google.com/p/xmemcached/w/list
author : dennis zhuang([email protected])
=============================================================
FAQ
1.How to build project by maven?
Type command "mvn -Dtest -DfailIfNoTests=false assembly:assembly" to build the project.Maven will download the dependencies automacly and build project.
2.How to run unit tests?
The test.properties file under the src/test/resources folder is used for setting memcached test server.
Please set test.memcached.servers property,Then run the AllTests class with jvm option "-ea".
3.Is Xmemcached compatible with jdk5?
Yes,since 1.2.0-RC1,Xmemcached is compatible with jdk5.
======================Example==================================
#New a XMemcachedClient instance
XMemcachedClientBuilder builder = new XMemcachedClientBuilder(
AddrUtil.getAddresses("localhost:11211"));
XMemcachedClient client=builder.build();
#If you want to use binary protocol(use memcached 1.4.0 and xmemcached 1.2.0)
XMemcachedClientBuilder builder = new XMemcachedClientBuilder(
AddrUtil.getAddresses("localhost:11211"));
builder.setCommandFactory(new BinaryCommandFactory());
XMemcachedClient client=builder.build();
#If you want to use xmemcached talking with kestrel
XMemcachedClientBuilder builder = new XMemcachedClientBuilder(
AddrUtil.getAddresses("localhost:11211"));
builder.setCommandFactory(new KestrelCommandFactory());
XMemcachedClient client=builder.build();
#If you want to store primitive type as String
client.setPrimitiveAsString(true);
#add or remove memcached server dynamically
client.addServer("localhost:12001 localhost:12002");
client.removeServer("localhost:12001 localhost:12002");
#get operation
String name =client.get("test");
#set add replace append prepend gets
client.add("hello", 0, "dennis");
client.replace("hello", 0, "dennis");
client.append("hello", 0, " good");
client.prepend("hello", 0, "hello ");
GetsResponse response=client.gets("hello");
long cas=response.getCas();
Obejct value=response.getValue();
#incr decr
client.set("a",0,"1");
client.incr("a",4);
client.deccr("a",4);
#cas
client.cas("a", 0, new CASOperation() {
@Override
public int getMaxTries() {
return 1; //max try times
}
@Override
public Object getNewValue(long currentCAS, Object currentValue) {
System.out.println("current value " + currentValue);
return 3;
}
});
#flush_all
client.flushAll();
#stats
Map<InetSocketAddress,Map<String,String>> result=client.getStats();
# get server versions
Map<InetSocketAddress,String> version=memcached.getVersions();
#bulk get
List<String> keys = new ArrayList<String>();
keys.add("hello");
keys.add("test");
Map<String, Object> map = client.get(keys);
#Enable jmx support
java -Dxmemcached.jmx.enable=true [YourApp]
Access MBean through service:jmx:rmi:///jndi/rmi://[host]:7077/xmemcachedServer
#Integrate to spring framework
<bean name="memcachedClient"
class="net.rubyeye.xmemcached.utils.XMemcachedClientFactoryBean">
<property name="servers">
<value>localhost:12000 localhost:12001</value>
</property>
</bean>
#Set server's weight
//set weight to 2
client.addServer("localhost",12000,2);
//or through XMemcachedClientBuilder,pass a weight array to XMemcachedClientBuilder constructor
MemcachedClientBuilder builder = new XMemcachedClientBuilder(AddrUtil.getAddresses("localhost:12000 localhost:12001"),new int[]{1,3});
builder.setSessionLocator(new KetamaMemcachedSessionLocator());
MemcachedClient memcachedClient=builder.build();
More information see wiki pages please.