Skip to content

Commit 57a3d2a

Browse files
committed
some basic docs
1 parent 4507c4f commit 57a3d2a

File tree

1 file changed

+117
-0
lines changed

1 file changed

+117
-0
lines changed

doc/HOWTO.txt

Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
Howto
2+
=====
3+
4+
Basic Example:
5+
==============
6+
7+
Lets say you have 3 servers. Server 1 and server 2 have 3GB of space
8+
and server 3 has 2GB of space for cache. Here is how I would set up
9+
my client.
10+
11+
import com.danga.MemCached.*;
12+
public class MyClass {
13+
14+
// create a static client as most installs only need
15+
// a single instance
16+
protected static MemCachedClient mcc = new MemCachedClient();
17+
18+
// set up connection pool once at class load
19+
static {
20+
21+
// server list and weights
22+
String[] servers =
23+
{
24+
"server1.mydomain.com:1624",
25+
"server2.mydomain.com:1624",
26+
"server3.mydomain.com:1624"
27+
};
28+
29+
Integer[] weights = { 3, 3, 2 };
30+
31+
// grab an instance of our connection pool
32+
SockIOPool pool = SockIOPool.getInstance();
33+
34+
// set the servers and the weights
35+
pool.setServers( servers );
36+
pool.setWeights( weights );
37+
38+
// set some basic pool settings
39+
// 5 initial, 5 min, and 250 max conns
40+
// and set the max idle time for a conn
41+
// to 6 hours
42+
pool.setInitConn( 5 );
43+
pool.setMinConn( 5 );
44+
pool.setMaxConn( 250 );
45+
pool.setMaxIdle( 1000 * 60 * 60 * 6 );
46+
47+
// set the sleep for the maint thread
48+
// it will wake up every x seconds and
49+
// maintain the pool size
50+
pool.setMaintSleep( 30 );
51+
52+
// set some TCP settings
53+
// disable nagle
54+
// set the read timeout to 3 secs
55+
// and don't set a connect timeout
56+
pool.setNagle( false );
57+
pool.setSocketTO( 3000 );
58+
pool.setSocketConnectTO( 0 );
59+
60+
// initialize the connection pool
61+
pool.initialize();
62+
63+
64+
// lets set some compression on for the client
65+
// compress anything larger than 64k
66+
mcc.setCompressEnable( true );
67+
mcc.setCompressThreshold( 64 * 1024 );
68+
}
69+
70+
// from here on down, you can call any of the client calls
71+
public static void examples() {
72+
mcc.set( "foo", "This is a test String" );
73+
String bar = mcc.get( "foo" );
74+
}
75+
}
76+
77+
Multi-client Example:
78+
=====================
79+
80+
If you need to support multiple clients (i.e. Java, PHP, Perl, etc.)
81+
you need to make a few changes when you are setting things up:
82+
83+
// use a compatible hashing algorithm
84+
pool.setHashingAlg( SockIOPool.NEW_COMPAT_HASH );
85+
86+
// store primitives as strings
87+
// the java client serializes primitives
88+
//
89+
// note: this will not help you when it comes to
90+
// storing non primitives
91+
mcc.setPrimitiveAsString( true );
92+
93+
// don't url encode keys
94+
// by default the java client url encodes keys
95+
// to sanitize them so they will always work on the server
96+
// however, other clients do not do this
97+
mcc.setSanitizeKeys( false );
98+
99+
100+
Failover/Failback Notes:
101+
========================
102+
103+
By default the java client will failover to a new server when a server
104+
dies. It will also failback to the original if it detects that the
105+
server comes back (it checks the server in a falling off pattern).
106+
107+
If you want to disable this (useful if you have flapping servers),
108+
there are two settings to handle this.
109+
110+
pool.setFailover( false );
111+
pool.setFailback( false );
112+
113+
114+
115+
Other:
116+
======
117+
See the java docs.

0 commit comments

Comments
 (0)