Does CouchDB have an equivalent to expire like in Redis?
Example for Redis expire:
#!/usr/bin/env python
import redis
redis_server = redis.Redis(host='localhost',port=5477,db=0)
r.set('cat','meow')
r.expire('cat',10)
# do some work and ten seconds later...
r.get('cat') # returns None
Redis
uses a lazy approach and deletes keys when they are inspected even though they may have expired much earlier. Also, as @antirez pointed out Redis will remove a random set of expired keys every second or so to keep the database size under control.
If CouchDB does not natively support this, you could add a tiny layer on top of your objects to do this work. Add an expiry field and when trying to retrieve objects, make sure expiry is in the future. If not, delete the expired objects. Furthermore, since deleted objects must persist (so the delete action can be replicated), you will also need to periodically find deleted documents and purge them.
Good question! The simple answer is "no" but another answer is mu.
The idiomatic CouchDB approach would be to have expires_at
timestamps in the records (documents). Next have a view, indexed by expiration timestamp. Clients would query the view keyed on timestamp, with the timestamp value greater or equal to now. The result will be a list of all valid documents.
This requires clients' clocks to be synchronized. If you have one central, authoritative server (a very common situation), an easy way to synchronize is for clients to ping couch and check its HTTP Date
header.
No. This is memcache/redis feature. CouchDB is data-persistent db.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With