Skip to main content
Version: 8.2405.x.x RR

Local store class function

nevis.localstore:instance()

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

The nevis.localstore does not survive a restart.

Local store object methods

store:put(key, value)

Stores a name-value pair with instance wide access. In case of a nil value, the entry is removed from the store.

Parameter types

  • key: String
  • value: String, number, nil

Example

store = nevis.localstore:instance()
store:put("yourKey", "your value")
store:put("yourKey", 5)
store:put("yourKey", 5.555)

To remove an entry:

store:put(“key”, nil)

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.

Parameter types

  • key: String
  • return: same as the saved value

Example

store = 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.

Parameter types

  • key: String
  • return: number

Example

store = nevis.localstore:instance()
value = store:increment("myCounter")

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.

Parameter types

  • key: String
  • return: number

Example

store = nevis.localstore:instance()
value = store:decrement("myCounter")

store:clear()

Removes all entries from the store.

Example

store = nevis.localstore:instance()
store:clear()

store:remove(key)

Removes the entry with the matching key from the store.

Parameter types

  • key: String

Example

store = nevis.localstore:instance()
store:remove("myCounter")

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.

Example

local store = nevis.localstore:instance()
function inputHeader(req, resp)
for n, v in store:iterate() do
req:setHeader(tostring(n), tostring(v))
end
end