Redis is an in-memory data structure store, used as a distributed, in-memory key–value database, cache and message broker, with optional durability. Redis supports different kinds of abstract data structures, such as strings, lists, maps, sets, sorted sets, HyperLogLogs, bitmaps, streams, and spatial indexes.[1]

Redis logo
Redis logo

Readings

edit
  1. Wikipedia: Redis
  2. Wikipedia: Key–value database

Activities

edit

Redis Environment

edit

Establish a Redis environment using one of the following:

Docker Playground

edit

Docker Playground is a free online Docker environment. It requires no installation or configuration.

  1. Use Play with Docker. Create an account and/or log in.
  2. Start an interactive session and add a new instance.
  3. In the terminal window, enter the following commands:
    • docker run -d --name=redis-server redis
    • docker exec -it redis-server bash
    • redis-cli

Redis in Docker

edit

You can use your own Docker environment to run MongoDB.

  1. Install Docker Desktop or the Docker Engine.
  2. In a terminal window, run the following commands:
    • docker run -d --name=redis-server redis
    • docker exec -it redis-server bash
    • redis-cli

Install Redis

edit

Install Redis on your own system.

  1. Review Redis: Quick Start
  2. Download and install Redis.
  3. Use the following terminal command to start the Redis server:
    • redis-server
  4. Use the following terminal command to access the Redis command interface:
    • redis-cli

Redis Activities

edit

Create a Database

edit
  1. Use the following Redis commands to select a database and set initial keys and values:
    SELECT 0
    MSET "Bulgaria" "45.2" "Canada" "45" "Federated States of Micronesia" "36.1" "Finland" "37.2" "Germany" "40.3" "Japan" "41" "Marshall Islands" "35.6" "Palau" "35" "Turkmenistan" "50.1"
  2. Use the following Redis command to show existing configuration information:
    INFO

Query a Database

edit
  1. Use the following Redis command to show existing keys in the current database:
    KEYS *
  2. Use the following Redis command to show an existing key value in the current database:
    GET "Canada"

Create a Key

edit
  1. Use the following Redis command to add a database key:
    SET "United States of America" "56.7"
  2. Use the following Redis command to display the inserted key:
    GET "United States of America"

Update a Key

edit
  1. Use the following Redis command to update a database key:
    SET "United States of America" "56.5"
  2. Use the following Redis command to display the updated key:
    GET "United States of America"

Delete a Key

edit
  1. Use the following Redis command to update a database key:
    DEL "United States of America"
  2. Use the following Redis command to display the remaining keys:
    KEYS *

Remove All Keys

edit
  1. Use the following Redis command to remove all keys:
    FLUSHALL
  2. Use the following Redis command to verify there are no remaining keys:
    KEYS *

See Also

edit

References

edit