Now I have some mappings, A->(A1, A2, A3, A4), B->(B1, B2, B3)
I wanna set the expire time of A1, A2, A3... as two days, so I can only get the values added within two days. And if all the values of A expired, the key A expired and should be deleted.
What solution or database can achieve this feature? Thanks very much.
####################################################-Well, I should describe this problem in more detail.
A lot of key-value pairs have been stored in Couchbase. And the key-value pairs are like this: {id1_20170306-00:01:00 => value1} {id1_20170306-10:01:00 => value2} {id2_20170306-00:01:00 => value3}
. The expiration time for all key-value pairs is two days.
When the user sends a request for id1
, all the key-value pairs whose keys start with id1
and not expired should be returned.
I have a solution that is not particularly good.
Convert the key to the start of the day. For 20170306-00:01:00
and 20170306-10:01:00
, it is 20170306-00:00:00
. Create a mapping like this
id1_20170306-00:00:00 => (id1_20170306-00:01:00,id1_20170306-10:01:00)
.
Set the expiration time of id1_20170306-00:00:00
to two days after the last modification.
When the user sends a request for id1, keys like id1_20170305-00:00:00
and id1_20170306-00:00:00
are generated to access the real keys stored in Couchbase.
Actually, the survive time of id1_20170306-00:01:00
is over two days.