Kong / lua-resty-counter

Lock-free counter for OpenResty
22 stars 11 forks source link

why use dict:incr() not dict:set() in reset() method #8

Open top628LJ opened 2 years ago

top628LJ commented 2 years ago

if I want to set the key to 0, i can't use reset(key, 0). I need to get a value, and then reset(key, value) ? i am not understand why use dict:incr() not dict:set() in reset() method

function _M:reset(key, number)
  if not number then
    return nil, "expect a number at #2"
  end
  return self.dict:incr(key, -number, number)
end