使用客户端

获取实例

通过指定server配置信息获取实例,Scala提供两种获取实例的接口:1、文件路径作为配置参数: 参见Java客户端文件配置

  1. def createClient(configPath: String): ScalaPegasusClient

例如:

  1. val pegasusClient = ScalaPegasusClientFactory.createClient("resource:///pegasus.properties")

2、Properties对象作为配置:

  1. def createClient(props: Properties): ScalaPegasusClient

例如:

  1. Properties pegasusConfig = new Properties();
  2. pegasusConfig.setProperty("meta_servers", "127.0.0.1:34601,127.0.0.1:34602,127.0.0.1:34603");
  3. pegasusConfig.setProperty("operation_timeout", 100);
  4. val pegasusClient = ScalaPegasusClientFactory.createClient(pegasusConfig)

数据操作

注意:调用函数前请确认导入Serializers._,详情参阅实现原理

  1. val hashKey = 12345L
  2. pegasusClient.set(table, hashKey, "sort_1", "value_1")
  3. val value = pegasusClient.get(table, hashKey, "sort_1").as[String]
  4. pegasusClient.del(table, hashKey, "sort_1")
  5. pegasusClient.exists(table, hashKey, "sort_1")
  6. pegasusClient.sortKeyCount(table, hashKey)
  7. pegasusClient.close