【问题标题】:Checking if an Astyanax Keyspace is null or doesn't exist检查 Astyanax 键空间是否为空或不存在
【发布时间】:2013-08-19 20:08:06
【问题描述】:

有没有办法检查当前上下文中是否存在 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();
}

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

【问题讨论】:

    标签: cassandra astyanax


    【解决方案1】:

    我就是这样子的……

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

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

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

    【讨论】:

    • 我认为这基本上就是我在上面所做的,但是使用 getKeyspaceProperties 方法而不是 describeKeyspace 方法。我一直在寻找类似 if(keyspace.getKeyspaceProperties() == null){ ... } 的东西
    猜你喜欢
    • 2014-08-05
    • 1970-01-01
    • 2017-12-26
    • 2012-07-29
    • 1970-01-01
    • 2018-10-26
    • 2011-11-04
    相关资源
    最近更新 更多