zoukankan      html  css  js  c++  java
  • Memcached(二)Memcached Java API基础之MemcachedClient

    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),如果没有则插入。

  • 相关阅读:
    numpy数据集练习——鸢尾花数据集
    git error:gpg failed to sign the data fatal: failed to write commit object
    后台定位Report
    iOS上传构建版本遇到的问题(Xcode8.1)
    动态计算UITableViewCell高度<进阶>
    计算代码运行时间
    安装Homebrew-包管理器
    SDWebImage : NSURLErrorDomain
    nil / Nil / NULL / NSNull
    NSURLCache
  • 原文地址:https://www.cnblogs.com/wuxinliulei/p/5217168.html
Copyright © 2011-2022 走看看