Using redis , there are many commands for retrieving entire data structures ( LRANGE for lists, SMEMBERS for sets, ZRANGE for sorted sets, and HGETALL for hashes).
Only the hash has a method ( HMSET ) to insert multiple elements with a single command.
All the examples I saw showed just adding one item at a time to a list (via RPUSH or LPUSH ) or a set (via SADD / ZADD ).
A more specific problem that I want to solve is the creation of lists and sorted sets containing database identifiers, these lists are unique for each user and contain from several hundred to several thousand identifiers.
Usually they are collected from a database query, massaged a bit in memory, and then stored in redis for pagination (lists) or set-based operations to extract subsets (sets and sorted sets).
I am currently repeating the list and calling the appropriate add method for each item. This has the disadvantages of having to perform multiple cable requests and repeat the key each time.
redis> RPUSH employee:ids 1000 (integer) 1 redis> RPUSH employee:ids 1001 (integer) 2 redis> RPUSH employee:ids 1002 (integer) 3 redis> RPUSH employee:ids 1003 (integer) 4 redis> del employee:ids (integer) 1
I think that using transaction with MULTI and EXEC may help turn it into a single request, but that will not help with the rekey.
redis> MULTI OK redis> RPUSH employee:ids 1000 QUEUED redis> RPUSH employee:ids 1001 QUEUED redis> RPUSH employee:ids 1002 QUEUED redis> RPUSH employee:ids 1003 QUEUED redis> RPUSH employee:ids 1004 QUEUED redis> EXEC 1. (integer) 1 2. (integer) 2 3. (integer) 3 4. (integer) 4 5. (integer) 5
Is there something that I am missing that will allow me to add items to lists / sets in the same command or without repeating the key every time?
I also use the jedis client library if that matters (or if there is another library that I can use from the JVM that would be better).