新建一个maven项目

1 导入依赖

com.taobao.tairtair-client2.3.5com.alibabafastjson1.2.59

2 编写测试代码

package com.example.demo;import com.alibaba.fastjson.JSON;import com.taobao.tair.DataEntry;import com.taobao.tair.Result;import com.taobao.tair.ResultCode;import com.taobao.tair.impl.DefaultTairManager;import java.util.ArrayList;import java.util.List;public class TestTair {public static void main(String[] args) {List configList = new ArrayList();configList.add("192.168.222.154:5198");//ConfigServer的ip和端口DefaultTairManager tairManager = new DefaultTairManager();tairManager.setConfigServerList(configList);tairManager.setTimeout(5000);tairManager.setCharset("utf-8");tairManager.setGroupName("group_test");//和配置中的组名称保持一致tairManager.init();//put数据ResultCode putResult = tairManager.put(1,"name","tairtest");System.out.println("putResult:"+putResult);System.out.println("putResult:"+ JSON.toJSONString(putResult));//get数据Result getResult = tairManager.get(1, "name");System.out.println("getResult:"+getResult);System.out.println("getResult:"+JSON.toJSONString(putResult));DataEntry dataEntry = getResult.getValue();System.out.println(JSON.toJSONString(dataEntry));//删除数据ResultCode delResult = tairManager.delete(1,"name");System.out.println("delResult:"+JSON.toJSONString(delResult));//获取数据Result getResult2 = tairManager.get(1,"name");System.out.println("getResult:"+getResult2);}}

3 运行结果如下