Search code examples
riak

retrieving keys by time lst written into riak DB


I am storing messages into a riak DB with sequence numbers as keys. When I am retrieving the messages, I used to sort all the keys and get each message in sorted order. Unfortunately that method has become non viable. Therefore I was wondering if riak itself timestamps each write, and if it is possible to retrieve messages in the order that they were written. I tried googling around but couldn't find anything.


Solution

  • No, Riak does not store the time a key was stored in any query-able form. If you are storing the messages in a JSON format that includes a time, you could use Riak Search to retrieve them by time. If you are using the LevelDB backend, you could add a secondary index to each item and retrieve them that way. Both of these methods only update the index when the key is stored, so it won't help already stored data, unless you read and rewrite it.