msys.counter.inc

March 26, 2020 Contributors

Name

msys.counter.inc — Increment a counter

Synopsis

msys.counter.inc(object_or_path);

object_or_path: mixed

Description

The first argument is either a path to a counter (for example, /sites/sit_name/errors) or a counter object that was returned by msys.counter.open. If a string is provided containing the path to a counter that does not exist, the counter is created with STRICT semantics. The counter value is atomically incremented. For performance reasons, use of counter handles is recommended. Find an example below.

require("msys.core");
require("msys.counter");

local mod = {};
local msys_emails = msys.counter.open("/sites/examples/messagesystems_correspondence");

function mod:validate_mailfrom(str, accept, vctx)
  str = tostring(str);
  if (string.find(str, "@messagesystems.com") != nil) then
    msys.counter.inc(msys_emails);
  end
  return msys.core.VALIDATE_CONT;
end

msys.registerModule("counter", mod);

require("msys.core");
require("msys.counter");

local mod = {};

function mod:validate_mailfrom(str, accept, vctx)
  str = tostring(str);
  if (string.find(str, "@messagesystems.com") != nil) then
    msys.counter.inc("/sites/site_name/messagesystems_correspondence");
  end
return msys.core.VALIDATE_CONT;
end

msys.registerModule("counter", mod);

Enable this function with the statement require('msys.counter');.

See Also

msys.counter.open, msys.counter.add, msys.counter.reset, msys.counter.unlink, counter