kv

Top  Previous  Next

The kv namespace allows you to store and share key value string pairs. These values are persisted between reboots. Note that the get function accepts wildcards using the "*" symbol. It is suggested that you create 'namespaces' for the keys. For example if you are working on a plugin that handles the toaster name your variables "toaster.burnTemperature".

Functions

Return Value

Signature

Description

 

get( key, getCallback )

Gets the values matching key and calls the callback function once complete.

 

set( keyValueTable, setCallback )

sets the values in keyValueTable in the KV storage. Calls callback when done.

 

delete ( keyTable, deleteCallback )

deletes the keys in keyTable and calls callback when done.

number

register( eventCallback )

registers for KV events


unregister( number)

unregisters for KV events

 

getCallback function signature

function ( table, success, timedout )

table contains the key-value table that match the query.

setCallback function signature

function ( success, timedout )

deleteCallback function signature

function ( success, timedout )

eventCallback function signature

function ( eventType, ... )

eventType can be "UPDATED", "DELETED"

eventCallback - UPDATED function signature

function ( eventType, keyValueTable )

eventCallback - DELETED function signature

function ( eventType, keyTable )

 

Example

The first example registers as a listener and prints all updated/new values on the lua console.

kv.register( function( event, kvs )

 

print(event)

if event == "UPDATED" then

   

    for key,value in pairs(kvs) do

        print(key, value)

    end

   

end

 

end)

 

This example sets a few values in the kv-store.

local kvs = {}

 

kvs["myvalues.hello"] = "dooodaa";

kvs["myvalues.bye"] = "yeehaaw";

 

kv.set(kvs, function( success )

      print("Set KV: " , success )

end)

 

This example shows how to retrieve values.

kv.get("myvalues.*", function( values, success )

 

  for key, value in pairs(values) do

      print(key, value)

  end

 

  print("Done")

 

end)

Availability

Lua

See Also

Javascript KV