Key Value Storage

Your Nimbella account has been provisioned with Key-Value Storage and Object Storage. In this document, we are going to cover Key-Value Storage.

A Key-Value Store, or KV for short, acts as a database where you create keys and apply values to those keys.

The following nim command will show the current contents of the KV. The command will not show any output if the KV is empty.

nim key-value list

This document divides into these parts:

  • Conceptual Overview
  • Using a Key-Value Storage inside actions using a Nimbella SDK
    • The nodejs SDK
    • The php SDK
    • The python SDK
  • Common Redis commands

Conceptual Overview

A KV behaves like a database where you can create keys, apply values to those keys, and then call on them to extract the data that you need.

In this visual example, you can store user info, such as their City, State, and Country, and apply the correct values to them. This allows you to keep track of data and request the data when needed.

Nimbella Key-Value Storage Example

The Nimbella KV uses Redis as the underlying implantation. Redis is data structure store that is used as a database for your actions.

Using a Key-Value Storage inside actions using a Nimbella SDK

Nimbella provides SDKs for use within actions. Currently, these exist for NodeJS, PHP, and Python. An SDK is under development for java and the plan is to eventually cover all supported languages.

Using the nodejs SDK

The nodejs SDK is a Node.js library that allows you to interact with Nimbella services.

In an action written in JavaScript, you should include

const nim = require('@nimbella/sdk')

To obtain a client for use with your data store, use

const redis = nim.redis();

You can view our GitHub Repo by clicking here

The php SDK

The php SDK is a PHP library that allows you to interact with Nimbella services.

In an action written in PHP, you should include

use Nimbella\Nimbella;

You can view our GitHub Repo by clicking here.

To obtain a client for use with your data store, use

$redis = $nim->redis();

The python SDK

The python SDK is a Python package that allows you to interact with Nimbella services.

In an action written in Python, you should include

import nimbella

To obtain a client for use with your data store, use

redis = nimbella.redis()

You can view our GitHub Repo by clicking here.

Common Redis commands

Here are some commonly used commands for Redis.

  • set - Set key to hold the string value.
  • get - Get the value of key.
  • incr -- Increments the value of the key.
  • exist - Returns if key exist.
  • del - Removes the specified keys.

Debugging your functions without redeploying

A nice feature when using KV is that you can change the behavior of the functions without redeploying!

In this example, you can use the debugging functionality in your KV.

const nimbella = require('@nimbella/sdk')
const kv = nimbella.redis()
async function main(args) {
if (await kv.getAsync('DEBUG_LEVEL') === 'debug') {
console.log('debugging enabled')
}
...
}