Edit this page on GitHub

Home > docs > plugins v2 > Key Value Task

Key Value Task

The key value kv task provides access to the server’s simple string key-value store. All data is project-scoped e.a. processes only see the values created by processes of the same project.

This task is provided automatically by Concord.


Setting a Value

Setting a string value:

- ${kv.putString("myKey", "myValue")}

Setting an integer (64-bit long) value:

- ${kv.putLong("myKey", 1234)}

Retrieving a Value

Using the OUT syntax of expressions:

- expr: ${kv.getString("myKey")}
  out: myVar

- log: "I've got ${myVar}"

Using the context:

- ${context.setVariable("myVar", kv.getString("myKey"))}
- log: "I've got ${myVar}"

In scripts:

- script: groovy
  body: |
    def kv = tasks.get("kv")

    def id = kv.inc(execution, "idSeq")
    println("I've got ${id}")

The execution variable is an alias for context and automatically provided by the runtime for all supported script engines. Check out the source code for all available public methods.

Integer values can be retrieved in the same way:

- log: "I've got ${kv.getLong('myKey')}"

Removing a Value

- ${kv.remove("myVar")}
- if: ${kv.getString("myVar") == null}
    - log: "Ciao, myVar! You won't be missed."

Incrementing a Value

This can be used as a simple sequence number generator.

- expr: ${kv.inc("idSeq")}
  out: myId
- log: "We got an ID: ${myId}"

Warning: the existing string values can’t be incremented.