Note that there are some explanatory texts on larger screens.

plurals
  1. POrecreate zdiffstore in Redis for Ruby
    primarykey
    data
    text
    <p>I am trying to create a transaction similar to a Redis sdiffstore for a sorted set. I have a Redis "main" (temp:'..u_id) sorted set and a second "remove" set. I want to return the "main" sorted set with scores after removing any matching members in the "remove" set. </p> <p>My structure has ~200 "main" keys with ~200 scored members in each. The "remove" set has ~50 members for each one of the main keys. For every request I need to loop through all ~200 users which is proving to be a costly process. Below is an portion of my existing server side script:</p> <pre><code>#Generate list of user ids local usercard = redis.call('smembers', 'temp:user') --#Loop through all available users --#Get array of users for i=1,table.getn(usercard)-1,1 do local u_id = usercard[i] --#Create a copy of the user and store into temp:user_id redis.call('zunionstore', 'temp:..u_id,1,'user:'..u_id) --#remove unwanted redis.call('zrem','temp:'..u_id, unpack(redis.call('smembers','remove:'..u_id))) end </code></pre> <p>The zunionstore and zrem combination is a very expensive command and the loop proves to be the limiting factor preventing the ability to scale. I know I am not making best use of the Redis thread as I cant scale past ~50 concurrent connections before everything bogs down.</p> <p>As I am relatively new to Redis:</p> <p>1) Is Redis the best db choice for challenge?</p> <p>2) Is there a more efficient key structure?</p> <p>3) Is there a more efficient way to structure the server side script or am I better off doing a pair of calls (zrange for the "main" sorted set and smembers for the "remove" set) to do the processing in Ruby given the big(O) will remain rather large?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload