Skip to main content
Version: 4.6.x.x LTS

Local store class function

nevis.localstore:instance()*

Gets the instance of the local store. A local store provides an instance with wide access to name-value pairs and atomic counters.

Note that nevis.localstore does not survive a restart or reinit.

MethodDescriptionExample
store:put(key, value)Stores a name-value pair globally.key: stringvalue: stringnumber
store:get(key)Gets a globally stored value with a given key. The type of the returned value is the same as the type of the put value. So the type of the Lua integrals and float numbers is retained.key: stringstore = nevis.localstore:instance()value = store:get("yourKey")
store:increment(key)Increments the value of the key and returns the new value. The system expects a key with an integral value, otherwise an error occurs. If the key had not been present yet, then a new key is created with the zero ("0") value. This is an atomic operation.key: stringstore = nevis.localstore:instance()value = store:increment("myCounter")-- value will be 0
store:decrement(key)Decrements the value of the key and returns the new value. The system expects a key with an integral value, otherwise an error occurs. If the key had not been present yet, then a new key is created with the zero ("0") value. This is an atomic operation.key: stringstore = nevis.localstore:instance()value = store:decrement("myCounter")-- value will be 0
store:clear()Removes all entries from the store.store = nevis.localstore:instance()store:clear()
store:iterate()Iterates over all entries. The type of the returned value is the same as the type of the put value. So the type of the Lua integrals and float numbers is retained. Be aware that nevisProxy stores a local copy for iterating. This can become a problem (of type OutOfMemoryException) if you have a big amount of entries or if you have huge entries.local store = nevis.localstore:instance()function inputHeader(req, resp) for n, v in store:iterate() do req:setHeader(tostring(n), tostring(v)) endend