實戰Memcached緩衝系統(2)Memcached Java API基礎之MemcachedClient

來源:互聯網
上載者:User

尊重知識,轉載請註明本文來自:編程藝術家Poechant的CSDN部落格 http://blog.csdn.net/poechant

1. 建構函式

public MemcachedClient(InetSocketAddress[] ia) throws IOException;

public MemcachedClient(List<InetSocketAddress> addrs) throws IOException;

public MemcachedClient(ConnectionFactory cf, List<InetSocketAddress> addrs) throws IOException;

其中最簡單的建構函式就是第一個,可以直接傳遞一個InetSocketAddress,也可以是InetSocketAddress的數組。其實InetSocketAddress也是被轉換成數組的。

比如:

MemcachedClient cache = new MemcachedClient(new InetSocketAddress("127.0.0.1", 11211));

2. 常用方法

一般快取資料的常用操作有:set(add+replace)、get、replace、add

public Future<Boolean> set(String key, int exp, Object o)

第一個參數:鍵(key)

第二個參數:到期時間(單位是秒)

第三個參數:要設定緩衝中的對象(value),如果沒有則插入,如果有則修改。

public Object get(String key)

第一個參數:鍵(key)

public Future<Boolean> replace(String key, int exp, Object o)

第一個參數:鍵(key)

第二個參數:到期時間(單位是秒)

第三個參數:該鍵的新值(new value),如果有則修改。

public Future<Boolean> add(String key, int exp, Object o)

第一個參數:鍵(key)

第二個參數:到期時間(單位是秒)

第三個參數:該鍵的值(value),如果沒有則插入。

尊重知識,轉載請註明本文來自:編程藝術家Poechant的CSDN部落格 http://blog.csdn.net/poechant

-

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.