4

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

Gideon
  • 2,211
  • 5
  • 29
  • 47

2 Answers2

2

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

Community
  • 1
  • 1
LFI
  • 654
  • 5
  • 11
0

You can easily use Redis pipeline. This feature could send batch of commands as single command. Here is example with Redisson framework:

String[] urls = ...

RBatch batch = redisson.createBatch();
RList<String> list = batch.getList("yourList");
for (int i = 0; i < 40; i++) {
      list.addAsync(urls[i]);
}
// send to Redis as single command
batch.execute();
Nikita Koksharov
  • 10,283
  • 1
  • 62
  • 71