Memcached Install - windows and linux

来源:互联网 发布:淘宝上怎么投诉快递 编辑:程序博客网 时间:2024/05/23 01:19

 

Outline

  • Outline
  • Install/Command
    • Linux
      • install
      • Commands
    • Windows
  • Client Usage/API
    • Java - spymemcached
  • Resources

Install/Command

Linux

Billing Team Manual
memcached FAQ

install

install libevent
libevent Download
libevent-1.4.12.tar.gz 2009-07-24
$ tar -zxvf libevent-1.x.x.tar.gz
$ ./configure --prefix=/usr/
$ make
$ make test
$ make install

install memcached
memcached Download
memcached-1.4.0.tar.gz - July 9th, 2009
$ tar -zxvf memcached-1.x.x.tar.gz
$ ./configure --prefix=/usr/local/memcached --with-libevent=/usr/ --enable-threads (you probably want threads)
$ make
$ make test
$ sudo make install

Commands

Start/Stop
text protocol

//startcd /usr/local/memcached/bin./memcached -d -m 100 -u root -p 11211 -c 256 -P /tmp/memcached.pid        -m memory allocated for memcached server, unit is MB        -u the user run memcached.        -l listen host ip address.        -p listen port number.        -c concurrent thread number.        -P the file saving memcached pid.//monitortelnet 172.16.100.117 11211//shutdownkill `cat /tmp/memcached.pid`

Storage
set key001 0 0 5
hello
$ STORED
get key001
$ VALUE key001 0 5
$ hello
$ END
delete key001
$ DELETED
get key001
$ END
set key001 0 0 5
hello
$ STORED
flush_all
$ OK
get key001
$ END

  • set <key> <flags> <exptime> <bytes>
  • flush_all : Its effect is to invalidate all existing items immediately (by default) or after the expiration specified.

Windows

memcached-win32

  • Download : version: 1.2.1 - Dec 23, 2006
  • unzip : Unzip the binaries in your desired directory (eg. c:/memcached)
  • setup : c:/memcached/memcached.exe -d install
  • start : c:/memcached/memcached.exe -d start

Client Usage/API

clients

Java - spymemcached

spymemcached
spymemcached javadoc

//connectMemcachedClient c=new MemcachedClient(    new InetSocketAddress("hostname", portNum));// Store a value (async) for one hourc.set("someKey", 3600, someObject);// Retrieve a value (synchronously).Object myObject=c.get("someKey");// Try to get a value, for up to 5 seconds, and cancel if it doesn't returnObject myObj=null;Future<Object> f=c.asyncGet("someKey");try {    myObj=f.get(5, TimeUnit.SECONDS);} catch(TimeoutException e) {    // Since we don't need this, go ahead and cancel the operation.  This    // is not strictly necessary, but it'll save some work on the server.    f.cancel(false);    // Do other timeout related stuff}

Resources

Inside into memcached, Chinese