KVS
The KVS (Key-Value Store) service provides a basic persistent storage of key-value pairs. Keys are strings and values can be any valid JSON value. The service is accessed thorugh RPC and the follwoing methods are provided: KVS.Set, KVS.Delete, KVS.Get, KVS.List and KVS.GetMany. Users of the API can use etag-based mechanism to ensure atomicity of updates. The following limits are enforced:
- Maximum Key Length = 42
- Maximum Value Length = 253
- Maximum Number of Keys Stored = 50
Additionally, a global revision number of the store is maintained which is incremented on every update.
KVS.Set
This method adds a new key-value pair to the store or updates an existing one.
Request
Parameters:
| Property | Type | Description |
|---|---|---|
| string | The key to be added or updated. Required |
| any JSON value | Value for the key. Required |
| string | Generated hash uniquely identifying the key-value pair. Optional |
- When
etagis present it should specify the value for existing pair and is checked against the one in the store so that and update is made only if they match. - Otherwise the update is rejected meaning that someone has changed the value after the last access.
- If
etagis not present and thekeydoes not exist it is added or if it exists it is updated unconditionally. - If
etagis present and thekeydoes not exist error is returned.
Response
Attributes in the result:
| Property | Type | Description |
|---|---|---|
| string | Generated hash of the newly created or updated item |
| number | Revision of the store (after update) |
KVS.Get
This method returns the value stored and etag for a given key. If the key does not exist error is returned.
Request
Parameters:
| Property | Type | Description |
|---|---|---|
| string | The key to be looked up. Required |
Response
Attributes in the result:
| Property | Type | Description |
|---|---|---|
| string | Generated hash of the requested item |
| any JSON value | The value for the key |
KVS.GetMany
This method returns the full information stored for items in the store based on an optinal key matching parameter.
Request
Parameters:
| Property | Type | Description |
|---|---|---|
| string | Pattern against which keys are matched. default is |
| number | Index of the list from which to start generating the result Optional |
If match is specified the keys are matched according to the following rules:
*matches zero or more characters?Matches exactly one character- ',' divides alternative patterns
- any other character matches itself
Match is case insensitive.
Response
Attributes in the result:
| Property | Type | Description |
|---|---|---|
| object | JSON object containing a set of JSON objects whose keys are the keys matched against the requested pattern with properties |
| number | Index of the first entry in the result |
| number | Total number of available entries |
KVS.List
This method returns a list of existing keys and etags based on an optional match parameter.
Request
Parameters:
| Property | Type | Description |
|---|---|---|
| string | Pattern against which keys are matched. default is |
If match is specified the keys are matched according to the following rules:
*matches zero or more characters until a slash character /**matches zero or more characters?Matches exactly one character which is not a slash /|or , divides alternative patterns- any other character matches itself
Match is case insensitive.
Response
Attributes in the result:
| Property | Type | Description |
|---|---|---|
| object | Whose keys are the keys which matched against the requested pattern and the only property of the corresponding |
| number | Current revision of the store |
KVS.Delete
This methods deletes existing key from the store.
Request
Parameters:
| Property | Type | Description |
|---|---|---|
| string | The key to be deleted. Required |
| string | Generated hash uniquely identifying the key-value pair. Optional |
- When
etagis present it should specify the value for existing pair and is checked against the one in the store so that the key is deleted only if they match. - Otherwise error is returned.
- If the
keydoes not exist error is returned.
Response
Attributes in the result:
| Property | Type | Description |
|---|---|---|
| number | Revision of the store (after delete) |
Examples
KVS.Set example
- KVS.Set HTTP GET Request
- KVS.Set Curl Request
- KVS.Set Mos Request
http://192.168.33.1/rpc/KVS.Set?key="item1"&value="item1 value"
curl -X POST -d '{"id":1,"method":"KVS.Set","params":{"key":"item1","value":"item1 value"}}' http://${SHELLY}/rpc
mos --port ${PORT} call KVS.Set '{"key":"item1","value":"item1 value"}'
Response
- KVS.Set HTTP GET Response
- KVS.Set Curl Response
- KVS.Set Mos Response
{
"etag": "0DWty8HwCB",
"rev": 2733
}
{
"id": 1,
"src": "shellyplus1-a8032abe54dc",
"params": {
"etag": "0DWty8HwCB",
"rev": 2733
}
}
{
"etag": "0DWty8HwCB",
"rev": 2733
}
KVS.Get example
- KVS.Get HTTP GET Request
- KVS.Get Curl Request
- KVS.Get Mos Request
http://192.168.33.1/rpc/KVS.Get?key="item1"
curl -X POST -d '{"id":1,"method":"KVS.Get","params":{"key":"item1"}}' http://${SHELLY}/rpc
mos --port ${PORT} call KVS.Get '{"key":"item1"}'
Response
- KVS.Get HTTP GET Response
- KVS.Get Curl Response
- KVS.Get Mos Response
{
"etag": "0DWty8HwCB",
"value": "item1 value"
}
{
"id": 1,
"src": "shellyplus1-a8032abe54dc",
"params": {
"etag": "0DWty8HwCB",
"value": "item1 value"
}
}
{
"etag": "0DWty8HwCB",
"value": "item1 value"
}
KVS.GetMany example
- KVS.GetMany HTTP GET Request
- KVS.GetMany Curl Request
- KVS.GetMany Mos Request
http://192.168.33.1/rpc/KVS.GetMany?match="item?"&offset=0
curl -X POST -d '{"id":1,"method":"KVS.GetMany","params":{"match":"item?","offset":0}}' http://${SHELLY}/rpc
mos --port ${PORT} call KVS.GetMany '{"match":"item?","offset":0}'
Response
- KVS.GetMany HTTP GET Response
- KVS.GetMany Curl Response
- KVS.GetMany Mos Response
{
"items": [
{
"key": "item1",
"etag": "0DhkTpVgJk9zc2soEXlpoLrw==",
"value": "value item1"
},
{
"key": "item2",
"etag": "0DXyU0CpLjyvZAV8GjRb2VzA==",
"value": "value item2"
}
],
"offset": 0,
"total": 26
}
{
"id": 1,
"src": "shellyplus1-a8032abe54dc",
"params": {
"items": [
{
"key": "item1",
"etag": "0DhkTpVgJk9zc2soEXlpoLrw==",
"value": "value item1"
},
{
"key": "item2",
"etag": "0DXyU0CpLjyvZAV8GjRb2VzA==",
"value": "value item2"
}
],
"offset": 0,
"total": 26
}
}
{
"items": [
{
"key": "item1",
"etag": "0DhkTpVgJk9zc2soEXlpoLrw==",
"value": "value item1"
},
{
"key": "item2",
"etag": "0DXyU0CpLjyvZAV8GjRb2VzA==",
"value": "value item2"
}
],
"offset": 0,
"total": 26
}
KVS.List example
- KVS.List HTTP GET Request
- KVS.List Curl Request
- KVS.List Mos Request
http://192.168.33.1/rpc/KVS.List?match="item"
curl -X POST -d '{"id":1,"method":"KVS.List","params":{"match":"item"}}' http://${SHELLY}/rpc
mos --port ${PORT} call KVS.List '{"match":"item"}'
Response
- KVS.List HTTP GET Response
- KVS.List Curl Response
- KVS.List Mos Response
{
"keys": {
"item1": {
"etag": "0DWty8HwCB"
},
"item2": {
"etag": "0DMHqWL0P0"
}
},
"rev": 2744
}
{
"id": 1,
"src": "shellyplus1-a8032abe54dc",
"params": {
"keys": {
"item1": {
"etag": "0DWty8HwCB"
},
"item2": {
"etag": "0DMHqWL0P0"
}
},
"rev": 2744
}
}
{
"keys": {
"item1": {
"etag": "0DWty8HwCB"
},
"item2": {
"etag": "0DMHqWL0P0"
}
},
"rev": 2744
}
KVS.Delete example
- KVS.Delete HTTP GET Request
- KVS.Delete Curl Request
- KVS.Delete Mos Request
http://192.168.33.1/rpc/KVS.Delete?key="item1"
curl -X POST -d '{"id":1,"method":"KVS.Delete","params":{"key":"item1"}}' http://${SHELLY}/rpc
mos --port ${PORT} call KVS.Delete '{"key":"item1"}'
Response
- KVS.Delete HTTP GET Response
- KVS.Delete Curl Response
- KVS.Delete Mos Response
{
"rev": 2739
}
{
"id": 1,
"src": "shellyplus1-a8032abe54dc",
"params": {
"rev": 2739
}
}
{
"rev": 2739
}