首页 > 解决方案 > 在 Aerospike 中,使用 C 客户端在 ops 中指定 ttl 的触摸操作不会重置为指定值。它重置为默认配置值

问题描述

as_status update_record_ttl(int ttl, const char *key) {
        as_operations ops;
        as_operations_inita(&ops, 1);
        as_operations_add_touch(&ops);

        ops.ttl = ttl;
        as_error err;
        as_key record_key;
        as_key_init_str(&record_key, g_namespace, g_set, key);
        if (aerospike_key_operate(&g_as, &err, NULL, &g_key, &ops, NULL) !=
                        AEROSPIKE_OK) {
                fprintf(stderr, "TTL update failed!! rc=%d\n", err.code);
        }
       as_operations_destroy(&ops);
       return err.code;
}

上面的代码旨在使用指定的值重置 ttl,但它只是将其重置为默认配置 ttl。我想用不同的值设置 ttl,而不是默认配置。任何人都可以帮助它。

谢谢

标签: caerospike

解决方案


Aerospike 服务器在每次写入操作(包括触摸)后重置记录的 ttl。如果未为写入操作设置所需的 ttl,则使用服务器默认 ttl。

完成任务的唯一方法是在对该记录的每个写入操作上设置相同的 ttl。在触摸操作上设置 ttl,然后在地图移除操作上再次设置相同的 ttl。


推荐阅读