2018.5.17 memcached

簡介java

Memcached是一個自由開源的,高性能,分佈式內存對象緩存系統。緩存

安裝app

yum install memcached分佈式

鏈接memcached

telnet HOST PORT性能

telnet 127.0.0.1 11211spa

存儲命令.net

Memcached set 命令code

Memcached addserver

Memcached replace

Memcached append

Memcached prepend

Memcached CAS

查找命令

Memcached get 

Memcached gets

Memcached delete

Memcached incr/decr

統計命令

Memcached stats

Memcached stats items

Memcached stats slabs

Memcached stats sizes

Memcached flush_all

java鏈接

import java.net.InetSocketAddress;
import java.util.concurrent.Future;
 
import net.spy.memcached.MemcachedClient;
 
public class MemcachedJava {
   public static void main(String[] args) {
   
      try{
         // 鏈接本地的 Memcached 服務
         MemcachedClient mcc = new MemcachedClient(new InetSocketAddress("127.0.0.1", 11211));
         System.out.println("Connection to server sucessful.");
      
         // 存儲數據
         Future fo = mcc.set("runoob", 900, "Free Education");
      
         // 查看存儲狀態
         System.out.println("set status:" + fo.get());
         
         // 輸出值
         System.out.println("runoob value in cache - " + mcc.get("runoob"));
 
         // 關閉鏈接
         mcc.shutdown();
         
      }catch(Exception ex){
         System.out.println( ex.getMessage() );
      }
   }
}
相關文章
相關標籤/搜索