Skip to content

Latest commit

 

History

History
201 lines (143 loc) · 5.41 KB

README.md

File metadata and controls

201 lines (143 loc) · 5.41 KB

Redis is an in-memory data structure store.

AboutDisclaimerGetting StartedDownloadHow To Use


About

Redis is an in-memory data structure store, used as a distributed, in-memory key–value database, cache and message broker, with optional durability.

You can learn about Redis in 100 Seconds by watching Fireship YouTube channel.

Disclaimer

Important

Localhost Databases is not affiliated with the databases' developers/owners and is not an official product.

Localhost Databases has been developed to run databases in a local Docker environment. To install a production instance, read the databases' respective installation guides.

Getting Started

You will need to make sure your system meets the following prerequisites:

  • Docker Engine >= 20.10.0

This repository utilizes Docker to run the Redis sample. So, before using the Redis, make sure you have Docker installed on your system.

Download

To use Redis, you can clone the latest version of Localhost Databases repository for macOS, Linux and Windows.

# Clone this repository.
$ git clone git@github.com:luisaveiro/localhost-databases.git --branch main --single-branch

You can locate the Redis Docker configuration in the databases directory.

# Navigate to the Redis folder.
$ cd localhost-databases/databases/redis

How To Use

There are a few steps you need to follow before you can have an Redis database set up and running in Docker container. I have outline the steps you would need to take to get started.

1. Environment Variables

Before you start a database in a Docker container, you will need to create a DotEnv file. The DotEnv file will allow you to configure your database's credentials and map a container's port.

Localhost Databases includes a .env.example file for Redis Database. You can run the following command in the terminal to create your DotEnv file.

# Navigate to a database.
$ cd databases/redis

# Create .env from .env.example.
$ cp .env.example .env

The Redis Docker Compose file uses the follow variables from the DotEnv file.

#--------------------------------------------------------------------------
# Docker env
#--------------------------------------------------------------------------

# The project name. | default: redis
APP_NAME="redis"

#--------------------------------------------------------------------------
# Database (Redis) env
#--------------------------------------------------------------------------

# The Redis database container name. | default: redis_db
DB_CONTAINER_NAME="${APP_NAME}_db"

#--------------------------------------------------------------------------
# Network env
#--------------------------------------------------------------------------

# Map the database container exposed port to the host port. | default: 6379
DB_PORT=6379

# The Docker network for the containers. | default: local_dbs_network
NETWORK_NAME="local_dbs_network"

#--------------------------------------------------------------------------
# Volume env
#--------------------------------------------------------------------------

# The database container data volume. | default: redis_db_data
DB_VOLUME_DATA_NAME="${DB_CONTAINER_NAME}_data"

Note

The Redis Docker image doesn't offer additional environment variables.

2. Start Docker container

To start the Redis container, you can run the following command:

# Navigate to Redis database.
$ cd databases/redis

# Run Docker Compose command.
$ docker compose up -d
Expected result

To check the Redis container is running and the port mapping is configured correctly, you can run the following command:

# List containers
$ docker ps  

You should see a similar output.

CONTAINER ID   IMAGE          COMMAND                  CREATED         STATUS                            PORTS                    NAMES
cd1bd4fb200d   redis:alpine   "docker-entrypoint.s…"   9 seconds ago   Up 8 seconds (health: starting)   0.0.0.0:6379->6379/tcp   redis_db

3. Stop Docker container

To stop the Redis container, you can run the following command:

$ docker compose down

4. Connect to Database

To connect to your Redis container from your database client, you will need to provide the following settings:

HOST=127.0.0.1
PORT="${DB_PORT}"
Expected result

Below is a screenshot of the settings used in TablePlus:

TablePlus settings for Redis
TablePlus settings for Redis.


GitHubLinkedInTwitter