Hi all,
I have a question about storing lua tables in nginx shared memory. As part of the init_by_lua script, I created a complex object using a lot of nested tables, and need to be able to read from this object on each request.
I've defined an ngx.shared.dict called Foo and in the init script, I set Foo.thing equal to the table that I want to store in nginx shared memory:
Defining ngx.shared.dict:
In the init script:
local Foo = ngx.shared.Foo;
local newThing = Thing:create();
...
Foo.thing = newThing;
On request:
local Foo = ngx.shared.Foo;
...
Foo.thing:lookup(Bar);
...
All seems to work absolutely fine, and I can get ngx.shared.Foo.tree and lookup values from the worker processes on request, but having read up on it I realise that this is very much not how ngx.shared.dict is supposed to work, which is meant to just be simple key-value pair storage. So my question is: Is this supposed to work? And if not, is this highly likely to break at some point? As I say, all works perfectly as I'd expect, but wanted to know if there may be non-obvious subtleties that may break it.
Alternatively, is there a cleaner way to store non-simple lua types in nginx shared memory, since tables can't be stored in a key-value pair?
Please bear with me, I'm a little bit new to Lua. :)