Joe Andrews
Joe Andrews

Reputation: 161

Redis Lua scripting with large loops

Which of the following loops will run quicker in a Redis Lua Script for 10,000 iterations. Or will they both run at the same speed.

Does accessing a redis key inside a lua script take the same amount of time as accessing a local variable, e.g a value at a specific index of a table.

local members = redis.pcall('smembers','10000memberset')

for i=1,table.getN(members) do

 local value = members[i]
  -- do some logic on the value

end

or

for i=1,10000 do

  local value = redis.pcall('get',i) 
  -- do some logic on the value

end

Thanks!

Upvotes: 6

Views: 6307

Answers (1)

Joe Andrews
Joe Andrews

Reputation: 161

After testing with a 1,000,000 item set and 1,000,000 keys in redis the second loop is 6 times quicker. 20.5s vs 3.1s.

Upvotes: 6

Related Questions