首页 文章

Aerospike TTL更新

提问于
浏览
2

我正在尝试使用python客户端将.put()更新为Aerospike中的现有记录 .

我很高兴地发现你实际上可以放入现有的记录,而不是更新这里显示的TTL(meta params):https://www.aerospike.com/apidocs/python/client.html?highlight=ttl#aerospike.Client.put . 我以前通过读取TTL然后在新的put上重新设置它来做到这一点 .

但是,我发现当你使用aerospike.TTL_DONT_UPDATE选项时,TTL会重置为命名空间中设置的cold-start-evict-ttl . 我该如何避免这种情况并保持以前的TTL不变?

Crossposted to Aerospike论坛:https://discuss.aerospike.com/t/aerospike-ttls-on-put/4993

1 回答

  • 2

    不发布示例代码的是“错误报告”,相当于在使用厕所后不洗手 . 如果您只提供服务器版本和Python客户端版本,它也会有所帮助 .

    ttl-test.py

    from __future__ import print_function
    import aerospike
    import sys
    from aerospike import exception as e
    from time import sleep
    
    config = { 'hosts': [ ('127.0.0.1', 3000) ] }
    
    try:
        client = aerospike.client(config).connect()
    except ex.ClientError as e:
        print("Error: {0} [{1}]".format(e.msg, e.code))
        sys.exit(1)
    
    key = ('test', 'demo', 'foo')
    
    try:
        # Write a record
        client.put(key, {
            'name': 'Hey Joe',
            'age': 66
            }, meta={'ttl': 4})
    except ex.RecordError as e:
        print("Error: {0} [{1}]".format(e.msg, e.code))
    client.put(key, {'z': 26}, meta={'ttl': aerospike.TTL_DONT_UPDATE})
    
    try:
        (key, meta) = client.exists(key)
        print(meta)
    except ex.RecordError as e:
        print("Error: {0} [{1}]".format(e.msg, e.code))
    
    sleep(5)
    
    try:
        (key, meta) = client.exists(key)
        print(meta)
    except ex.RecordError as e:
        print("Error: {0} [{1}]".format(e.msg, e.code))
    
    client.close()
    

    现在来测试一下:

    $ python ttl-test.py 
    {'gen': 2, 'ttl': 4}
    None
    

    似乎工作 . 请注意,我使用的是服务器版本> = 3.10.1

相关问题