0

I'm trying to figure out the most efficient way to clear multiple keys using array of userIds for my auction site.

When a user places a bid on a specific auction then their userId gets added to array of bidders on that specific auction. The key is used for the active bids page. If a user places a bid, then the other bidders in the biddingGroup need to have their keys cache cleared. The only way I can think of doing it is to

  for (let i = 0; i < biddingGroup.length; i++) {
            redisConnection.client.del("active-bid-" + biddingGroup[i], function (err, response) {
              if (response == 1) {
                console.log("Deleted active bid pages from cache")
              } else {
                console.log("Cannot delete")
              }
            })
          }

but I feel this is inefficient. Is there a better way? I appreciate any help!

1 Answer 1

1

This loopless approach should be more efficient if we're talking about 10s or 100s of keys:

redisConnection.client.del(...biddingGroup.map(e => `active-bid-${e}`), function (err, response) {
// code
}

For 1000s or more, using wrapping it in a loop that handles about 100..1000 keys at a time makes sense imo.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.