Skip to main content

Run a transaction on process dict (proc_dict_run)

Declaration

ret, err = proc_dict_run(tx_code)

Parameters

  • tx_code
    String. The Lua code to execute as a transaction.

Returns

  • ret
    String | nil. On success, returns the value returned by the code; on failure, returns nil.
  • err
    String | nil. On success, returns nil; when code errors, returns error message.

Notes

  • Available for versions after 20250427.
  • All process queues whose names start with "xxtouch." or "1ferver." are preserved.
  • Execute process-dict transaction code; during execution, other threads are blocked from calling proc_ functions.
  • Maximum 1,000,000 lines per single run.
  • If successful, the code may return a string value which will be returned to the caller. If the code returns nil, an empty string will be returned to the caller.
  • On failure, returns nil and error message.
Allowed modules and functions in transaction Lua code

base (excluding require)
table
string
math
utf8
bit32
json
os.time()
os.clock()
sys.mtime()
utils.gen_uuid()
proc_put(key, value)
proc_get(key)
proc_queue_push_back(key, value)
proc_queue_push_front(key, value)
proc_queue_pop_front(key)
proc_queue_pop_back(key)
proc_queue_pop_value(key, value)
proc_queue_count_value(key, value)
proc_queue_clear(key)
proc_queue_read(key)
proc_queue_size(key)

Example

function proc_inc(key, int_value)
return proc_dict_run(string.format([[
local key = %q
local value = %d
local ov = proc_get(key)
if ov == '' then
ov = 0
else
ov = tonumber(ov)
end
if not ov then
error('not a number')
end
proc_put(key, tostring(ov + value))
return ov
]], key, int_value))
end

for i = 1, 20 do
nLog(proc_inc('haha', 10))
end