Search code examples
pythonaerospike

Aerospike set TTL for all filtered records with Python


I want to set the TTL to -1 (no ttl) for all records that match some filter, using Python.

I successfully set the TTL for all the records with the following:

import time

from aerospike_helpers import expressions as exp
from aerospike_helpers.operations import operations

import aerospike

if __name__ == '__main__':
    config = {
        'hosts': [('127.0.0.1', 3000)]
    }

    client = aerospike.client(config).connect()

    ops = [operations.touch(-1)]

    query = client.query('ns123', 'foo')
    query.add_ops(ops)
    expr = exp.GE(exp.LastUpdateTime(), 0).compile()
    policy = {}
    job_id = query.execute_background(policy)
    while True:
        response = client.job_info(job_id, aerospike.JOB_SCAN)
        print(response)
        if response["status"] != aerospike.JOB_STATUS_INPROGRESS:
            break
        time.sleep(0.25)

    client.close()

It works, but it produces a deprecationWarning: TTL should be specified in the meta dictionary for operate. the documentation states:

ttl (int): Deprecated. The ttl that should be set for the record.
    This should be set in the metadata passed to the operate or
    operate_ordered methods.

But how I can do it with operate or operate_oredered methods? seems like both require keys, and I'm doing this query on all records.


Solution

  • This deprecation requires update to Python client which should be forthcoming.