Part-7: - Interaction with the key-val store from the CLI
Tutorial overview
- Part 1 - Introduction to key-value store
- Part 2 - Basic operation get, set and delete key-values
- Part 3 - Increment and decrement operations
- Part 4 - Working with multiple values and streams
- Part 5 - Managing data with TTL options
- Part 6 - Multiple key spaces
- Part 7 - Interaction with the key-val store from the CLI
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:
- Set a value:
coho set <key> <value>
- Get a value:
coho get <key>
- 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.