# Server-Side Scripting/Key-Value Databases

This lesson introduces key-value database processing.

## Objectives and Skills

Objectives and skills for this lesson include:
* Understand NoSQL database concepts
* Understand key-value database concepts
* Use a key-value database with server-side scripts

## Readings

* Wikipedia: NoSQL
* Wikipedia: Key–value database

## Multimedia

* YouTube: Redis NoSQL
* YouTube: Redis Caching

## Tutorials

Before trying to work with any database using a programming language, you should first be familiar with that database's command language. The following tutorials will be helpful in understanding how to use Redis.
* Redis
* TutorialsPoint: Redis Tutorial

## Examples

The following examples use Redis as the key-value database. A similar approach would work for almost any key-value-based database.
* Go
* Node.js (Express)
* PHP
* Python (FastAPI)
* Python (Flask)

## Activities

Complete the following activities using HTML, CSS, and a server-side scripting language. Apply best practices for user interface design and your selected scripting language, including modules, comments, indentations, naming conventions, and constants. Use HTML forms and input elements for input, server-side scripts for processing, and HTML elements for output. Use separate functions for each type of processing. Avoid global variables by passing parameters and returning results. Add comments at the top of the code modules and include references to any resources used. Add the completed code to your website as /lesson11.
* Create an application that allows the user to insert, update, and delete records in a key-value database. After each action, display the current records. Use any key-value database and data structure you like. Be sure to include date, text, and number field types in the data structure. If in doubt, any of the previous cyclone, earthquake, or wildfire activities may be used as data examples.

## Lesson Summary

* A key-value database (sometimes called a key-value store) uses a simple key-value method to store data. These databases contain a simple string (the key) that is always unique and an arbitrary large data field (the value). They are easy to design and implement.
* An in-memory database relies on memory (RAM) for data storage rather than disks or SSDs. It is exceptionally fast for read and write operations, but data is not persistent.
* Keys are the field used to represent a dataset in a key:value database. The key in key:value.
* A common practice is to use dots, dashes, or colons to make multi-word keys more readable, for example, “user:1000” or “poet:Dickinson”.
* Strings are the most basic type of value you can create and manage. Keys that store strings can only hold one value, but that string value can hold any type of data up to 512MB.
* Redis provides data structures such as strings, hashes, lists, sets, sorted sets with range queries, bitmaps, hyperloglogs, geospatial indexes, and streams.
* One of the data types for the values in a Redis key-value database is lists. Using a linked list of strings is an efficient operation regardless of the size of the value. The possibilities offered by linked lists make them an ideal data type for storing real-time data updates, such as social media posts or logs.
* Redis also can be used to store JSON data. It has a few drawbacks, but it is another option for Redis to store data.
* Hashes are a map between string fields and string values, this data type is best to represent objects.
* Use cases for key-value databases include: Session management on a large scale, using cache to accelerate application responses , storing personal data on specific users, product recommendations, storing personalized lists of items for individual customers, managing each player’s session in massive multiplayer online games.
* Redis persistence performs point-in-time snapshots of your dataset at specified intervals.
* Redis replication copies data to multiple Redis nodes in a cluster, which improves request performance and provides data persistence if some nodes go down, providing high availability.

## See Also

* Databases
* Redis
* DigitalOcean: How To Manage a Redis Database Tutorial Series
* Medium: Introduction to Caching (Redis + Node.js)