Skip to content

Instantly share code, notes, and snippets.

@helenhash
Last active November 6, 2024 05:17
Show Gist options
  • Save helenhash/b14532e4b8d4ab6656fee56f0a4ec9f3 to your computer and use it in GitHub Desktop.
Save helenhash/b14532e4b8d4ab6656fee56f0a4ec9f3 to your computer and use it in GitHub Desktop.

Redis Setup & Testing

What

Redis is an open-source, in-memory data structure store often used as a database, cache, and message broker.

It supports various data structures like strings, hashes, lists, sets, and sorted sets

Keys

  • Replication: Supports master-slave replication, making it suitable for high-availability setups.
  • Pub/Sub Messaging: Allows message publishing and subscribing, making it useful for real-time messaging applications.

Setup

  • Docker compose file
version: '3'

services:
  redis:
    image: redis:latest
    container_name: my_redis
    ports:
      - "6379:6379"
    volumes:
      - redis_data:/data
    restart: unless-stopped

volumes:
  redis_data:
  • Run docker compose file

docker-compose up -d

  • Check status

docker ps -a

Connect

With the redis-cli command line tool

  • connect to Redis using the Redis CLI

(Redis CLI is part of the Redis package, so installing Redis will also install the CLI)

(Redis CLI is a powerful tool for working with Redis directly from the terminal)

docker exec -it redis_container redis-cli

https://redis.io/docs/latest/develop/connect/cli/

Use Redis Insight as a graphical user interface

Install Redis Insight (using browser)

(As of RedisInsight version 2.x, the default internal port has changed to 5540 instead of 8001)

version: '3.8'

services:
  redisinsight:
    image: redis/redisinsight:latest
    container_name: redisinsight
    ports:
      - "8080:5540"   # Map host port 8080 to container port 5540
    volumes:
      - redisinsight_data:/data   # Attach the volume to /data in the container
    restart: unless-stopped

volumes:
  redisinsight_data:
  • Add a New Redis Database in RedisInsight

Host: Enter host.docker.internal if you’re using Docker Desktop (for macOS or Windows), or localhost if using Docker on Linux.

Port: Enter 6379, which is the default Redis port.

Via a client library for your programming language

Client libraries Redis for VS Code

Store and retrieve data

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment