Skip to main content

Part-7: - Interaction with the key-val store from the CLI

Tutorial overview

Welcome to this part-7 of the key-value database tutorial for codehooks.io serverless Node.js backend.

In this section we'll cover how you can work with the key-value database using the Command Line Interface (CLI).

The Codehooks.io CLI is an essential component of many developers' workflows, this is also true when working with the key-value database.

The CLI har 3 basic operations for working with the key-value database:

  1. Set a value: coho set <key> <value>
  2. Get a value: coho get <key>
  3. Delete a value: coho del <key>

Let's go through some simple CLI examples showing how to work with the database keys and values.

Setting a new key-value

coho set 'my-first-value' 'This is the first value'

# CLI output
{ key: 'my-first-value', value: 'This is the first value' }

Setting another key-value

coho set 'my-second-value' 'This is the second value'

# CLI output
{ key: 'my-second-value', value: 'This is the second value' }

Getting a key-value

coho get 'my-second-value'

# CLI output
{ key: 'my-second-value', value: 'This is the second value' }

Getting multiple key-value(s) by key pattern

coho get 'my-*'           

# CLI output
{ key: 'my-first-value', val: 'This is the first value' }
{ key: 'my-second-value', val: 'This is the second value' }

2 keys

Setting a key-value with Time To Live (TTL)

coho set 'my-short-lived-value' 'I will be gone in 60 seconds' --ttl 60000

# CLI output
{ key: 'my-short-lived-value', value: 'I will be gone in 60 seconds' }

Deleting a key-value

coho del 'my-first-value'

# CLI output
{ key: 'my-first-value' }

This concludes our seven parts tutorial on how to develop with the key-value store in codehooks.io.

Read more about the key-value database API here.