使用客户端
获取实例
通过指定server配置信息获取实例,Scala提供两种获取实例的接口:1、文件路径作为配置参数: 参见Java客户端文件配置
- def createClient(configPath: String): ScalaPegasusClient
例如:
- val pegasusClient = ScalaPegasusClientFactory.createClient("resource:///pegasus.properties")
2、Properties对象作为配置:
- def createClient(props: Properties): ScalaPegasusClient
例如:
- Properties pegasusConfig = new Properties();
- pegasusConfig.setProperty("meta_servers", "127.0.0.1:34601,127.0.0.1:34602,127.0.0.1:34603");
- pegasusConfig.setProperty("operation_timeout", 100);
- val pegasusClient = ScalaPegasusClientFactory.createClient(pegasusConfig)
数据操作
注意:调用函数前请确认导入Serializers._
,详情参阅实现原理
- val hashKey = 12345L
- pegasusClient.set(table, hashKey, "sort_1", "value_1")
- val value = pegasusClient.get(table, hashKey, "sort_1").as[String]
- pegasusClient.del(table, hashKey, "sort_1")
- pegasusClient.exists(table, hashKey, "sort_1")
- pegasusClient.sortKeyCount(table, hashKey)
- pegasusClient.close