3.wget http://www.memcached.org/files/memcached-1.4.20.tar.gz
下载最新的安装文件memcached-1.4.20.tar.gz
4.tar -zxvf memcached-1.4.20.tar.gz
5.cd memcached-1.4.20
6。 ./configure && make && make test && sudo make install
提示报错:
checking build system type... x86_64-unknown-linux-gnu
checking host system type... x86_64-unknown-linux-gnu
checking target system type... x86_64-unknown-linux-gnu
checking for a BSD-compatible install... /usr/bin/install -c
checking whether build environment is sane... yes
checking for a thread-safe mkdir -p... /bin/mkdir -p
checking for gawk... gawk
checking whether make sets $(MAKE)... yes
checking for gcc... no
checking for cc... no
checking for cl.exe... no
configure: error: in `/opt/memcached-1.4.20':
configure: error: no acceptable C compiler found in $PATH
See `config.log' for more details.
显示正常结果,说明服务成功启动了。
stats
STAT pid 2940
STAT uptime 407
STAT time 1409821965
STAT version 1.4.20
STAT libevent 1.4.13-stable
STAT pointer_size 64
STAT rusage_user 0.000000
STAT rusage_system 0.029995
STAT curr_connections 5
STAT total_connections 6
STAT connection_structures 6
STAT reserved_fds 20
STAT cmd_get 0
STAT cmd_set 0
STAT cmd_flush 0
STAT cmd_touch 0
STAT get_hits 0
STAT get_misses 0
STAT delete_misses 0
STAT delete_hits 0
STAT incr_misses 0
STAT incr_hits 0
STAT decr_misses 0
STAT decr_hits 0
public class MyClass {
// create a static client as most installs only need
// a single instance
protected static MemCachedClient mcc = new MemCachedClient();
// set up connection pool once at class load
static {
// server list and weights
// String[] servers = { "server1.mydomain.com:1624",
// "server2.mydomain.com:1624", "server3.mydomain.com:1624" };
String[] servers = { "10.11.1.219:11211" };
// Integer[] weights = { 3, 3, 2 };
Integer[] weights = { 3};
// grab an instance of our connection pool
SockIOPool pool = SockIOPool.getInstance();
// set the servers and the weights
pool.setServers(servers);
pool.setWeights(weights);
// set some basic pool settings
// 5 initial, 5 min, and 250 max conns
// and set the max idle time for a conn
// to 6 hours
pool.setInitConn(5);
pool.setMinConn(5);
pool.setMaxConn(250);
pool.setMaxIdle(1000 * 60 * 60 * 6);
// set the sleep for the maint thread
// it will wake up every x seconds and
// maintain the pool size
pool.setMaintSleep(30);
// set some TCP settings
// disable nagle
// set the read timeout to 3 secs
// and don't set a connect timeout
pool.setNagle(false);
pool.setSocketTO(3000);
pool.setSocketConnectTO(0);
// initialize the connection pool
pool.initialize();
// lets set some compression on for the client
// compress anything larger than 64k
// mcc.setCompressEnable(true);
// mcc.setCompressThreshold(64 * 1024);
}
// from here on down, you can call any of the client calls
public static void examples() {
mcc.set("foo", "This is a test String");
ArrayList a1=new ArrayList();
a1.add(0);
a1.add(388);
a1.add(989);
a1.add("中文内容");