有没有一种方法可以检查当前上下文中是否存在Astyanax键空间?现在,我的代码执行以下操作:

keyspace = context.getClient();
try{
   keyspace.describeKeyspace();
}catch (BadRequestException e){
   keyspace.createKeyspace(ImmutableMap.<String, Object>builder()
                .put("strategy_options", ImmutableMap.<String, Object>builder()
                        .put("replication_factor", "1")
                        .build())
                .put("strategy_class", "SimpleStrategy")
                .build();
}


这是检查键空间是否存在的唯一方法吗?

最佳答案

我正在这样做...

try {
    keyspace.getKeyspaceProperties();
    LOG.debug("keyspace exist");
} catch (Exception e) {
    LOG.debug("keyspace does NOT exist");
}


此代码将生成异常,因此请务必添加一些注释。如果人们检查日志,他们将了解发生了什么

更新
有人在github上提出了功能请求
Issue #382
希望对您有帮助...

09-30 17:56