Wednesday, August 28, 2013

[Couchbase] How to retrieve a key expiration date

It is pretty easy to retrieve a key expiration date from couchbase, but if just like me you have been googling around without any success, and didn't find any thing relevant in the couchbase doc, here is what i came up with after inspecting my browser's network pane while on the admin console :

curl -v "http://couchbaseServer:couchbasePort/couchBase/bucketName/itemID"
(...)
< HTTP/1.1 200 OK
< Date: Tue, 27 Aug 2013 22:20:02 GMT
< Server: MochiWeb/1.0 (Any of you quaids got a smint?)
< X-Couchbase-Meta: {"id":"itemID","rev":"1-0007992d08e3d5750000000000000000","expiration":0,"flags":0,"type":"json"}
< Content-Type: application/json
< Content-Length: 365
< Cache-Control: must-revalidate
< Connection: close
* Closing connection #0
{"someObject":["foo", "bar"]}

To make a long story short, you can retrieve all the item metadata including the expiration, when reading the X-Couchbase-Meta http response header after an HTTP API call to the corresponding item

You can get a detailed explanation on the expiration value and how to set and read it at : http://www.couchbase.com/docs/couchbase-devguide-2.0/about-ttl-values.html

Short version :

  - If Expiry is less than 30*24*60*60 (30 days) : The value is interpreted as the number of seconds from the point of storage or update.
  - If Expiry is greater than 30*24*60*60 : The value is interpreted as the number of seconds from the epoch (January 1st, 1970).
  - If Expiry is 0 : This disables expiry for the item.


No comments: