Search code examples
javaredisvert.xvertx3

Storing a list of values with timestamp in Redis


I'm working with Vertx and Redis and I need to store triplets of (url, words, date).

Words is a list of values and not just a long string because when I query for these words I want to work on a list of strings. The date should be updated everytime I check if the URL exists in Redis

And so my questions are:

  1. Is it possible to store a list of values in Redis without using something like LPUSH or RPUSH? I don't want to use these because I have about 40 words for each URL and I don't want to create 40 requests for a single URL every time
  2. Is it possible to add a date field where it can be updated everytime I query for it? Or should I instead check if it exists and if it does update it manually?

I've seen many examples of how to solve these using LPUSH (or something similar) but as I said I want to create one insertion request and be done with it, similarly, I would like to get the results with as few as possible (ideally 1) request

Thanks in advance


Solution

  • If your Redis server > 2.4 you can LPUSH (doc) multiple values at once.

    Alternatively, you can use Redis transaction to do multiple command at once.

    I'm not aware of a command which allows you to get the creation/update date of a key, I think you have to create it manually like in this SO question