【问题标题】:How to get Null values of records in aerospike如何在 aerospike 中获取记录的 Null 值
【发布时间】:2017-07-05 13:04:52
【问题描述】:

我正在使用 aerospike。使用 AQL,我插入了一些数据。我想在 aerospike 中获取具有特定字段的记录的空值。我在该图片中标记图片一条记录没有名称它的空白空间

【问题讨论】:

    标签: null record aerospike aql


    【解决方案1】:

    Aeropsike 是无模式的 - 每条记录都是自我描述的。任何非空的 bin 都是记录的一部分。任何更新为 null 的 bin 实际上都会从记录中删除。因此,考虑记录单位而不是带有列的表。您可以从记录中查询特定的 bin,如果未找到,Aeropsike 将返回 null。这是java API:

    public final Record get(Policy policy,
             Key key,
             String... binNames)
                     throws AerospikeException
    Read record header and bins for specified key. The policy can be used to specify timeouts.
    Specified by:
    get in interface IAerospikeClient
    Parameters:
    policy - generic configuration parameters, pass in null for defaults
    key - unique record identifier
    binNames - bins to retrieve
    Returns:
    if found, return record instance. If not found, return null.
    Throws:
    AerospikeException - if read fails
    

    【讨论】:

    • 您能否详细说明当我将 null 放在垃圾箱上时会发生什么?那是删除垃圾箱的过程吗?发生了什么?记录的 LUT 是否在将 null 插入到 bin 时更新?它是通过 XDR 发货的吗?
    • null --> 删除一个 bin,是的。发生了什么? --> 使用更新的 LUT 在系统中重写记录的更新版本。如果您使用 XDR,这将导致该记录通过 xdr 发送。
    【解决方案2】:

    运行一些测试代码 - 记录密钥对其他一些 bin 有效:

    userRecord = client.get(null, userKey, "notThereBin");
        if (userRecord != null) {
            console.printf("\nINFO: User record with notThereBin read successfully! Here are the details:\n");
            console.printf("notThereBin:  " + userRecord.getValue("notThereBin") + "\n");
        } else {
            console.printf("ERROR: User record not found!\n");
        }
    

    输出是:

        INFO: User record with notThereBin read successfully! Here are the details:
    
    notThereBin:  null
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-01-29
      • 1970-01-01
      • 1970-01-01
      • 2021-09-19
      相关资源
      最近更新 更多