重置/更新 Couchbase 计数器的 TTL
Resetting / Updating TTL for a Couchbase counter
(这是一个非常简单的问题 - 可以通过尝试来回答 - 但由于文档没有明确说明,我想我会在这里记录它)
当我设置一个新的 TTL 沙发底座计数器时(例如,在 python 中使用 incr())- 然后使用 另一个[=25 重新 incr() 计数器=] TTL值,key的TTL会重置为新值吗?
这是另一种提问方式:
如果我运行下面的代码:
cb.incr(key='mykey',amount=1,initial=1,ttl=10) //10 seconds TTL
cb.incr(key='mykey',amount=1,initial=1,ttl=100) //will this update the TTL?
密钥会在 10 秒或 100 秒后过期吗?
python 库文档:http://docs.couchbase.com/sdk-api/couchbase-python-client-1.2.3/api/couchbase.html
所以答案是否定的:第二次调用 incr() 不会更新 TTL,但会成功增加计数器。
令人困惑的是,.set() API(或 upsert() API)并非如此。例如下面的代码
print cb.set('hello',{'hi':'there'},ttl=1)
print cb.set('hello',{'hi':'there'})
将生成非 TTL 文档 - 第二次调用 set() 会删除 TTL。
不,第二个 incr
操作不会 更新 TTL。如果您确实想更改 TTL,请使用 touch
命令。
请注意,这与原始 memcached 协议的行为相匹配 - 请参见示例 How does incr work with expiry times?
(这是一个非常简单的问题 - 可以通过尝试来回答 - 但由于文档没有明确说明,我想我会在这里记录它)
当我设置一个新的 TTL 沙发底座计数器时(例如,在 python 中使用 incr())- 然后使用 另一个[=25 重新 incr() 计数器=] TTL值,key的TTL会重置为新值吗?
这是另一种提问方式:
如果我运行下面的代码:
cb.incr(key='mykey',amount=1,initial=1,ttl=10) //10 seconds TTL
cb.incr(key='mykey',amount=1,initial=1,ttl=100) //will this update the TTL?
密钥会在 10 秒或 100 秒后过期吗?
python 库文档:http://docs.couchbase.com/sdk-api/couchbase-python-client-1.2.3/api/couchbase.html
所以答案是否定的:第二次调用 incr() 不会更新 TTL,但会成功增加计数器。
令人困惑的是,.set() API(或 upsert() API)并非如此。例如下面的代码
print cb.set('hello',{'hi':'there'},ttl=1)
print cb.set('hello',{'hi':'there'})
将生成非 TTL 文档 - 第二次调用 set() 会删除 TTL。
不,第二个 incr
操作不会 更新 TTL。如果您确实想更改 TTL,请使用 touch
命令。
请注意,这与原始 memcached 协议的行为相匹配 - 请参见示例 How does incr work with expiry times?