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.

0

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.