Skip to content

Latest commit

 

History

History
76 lines (44 loc) · 2.16 KB

README.md

File metadata and controls

76 lines (44 loc) · 2.16 KB

Redis Pub/Sub Chat Application

This is a simple real-time chat application built with Go, WebSockets, and Redis Pub/Sub. Users can join the chat by connecting to the WebSocket server and will receive messages from other users in real-time.

Features

  • Real-Time Communication: Messages are sent and received instantly using WebSockets.
  • Redis Pub/Sub: Used to broadcast messages to all connected users efficiently.
  • Graceful Shutdown: Ensures all connections are closed properly when the server shuts down.

Prerequisites

  • Go (version 1.16 or later)
  • Redis server (running on localhost:6379 by default)

Getting Started

1. Clone the Repository

git clone https://github.com/yourusername/redis-chat-app.git
cd redis-chat-app

2. Install Dependencies

This application uses the github.com/go-redis/redis/v8 and github.com/gorilla/websocket packages. You can install them with:

go get github.com/go-redis/redis/v8
go get github.com/gorilla/websocket

3. Configure Redis

Ensure your Redis server is running on localhost:6379. If it's hosted elsewhere, update the redisAddr constant in the code to reflect the correct address.

4. Run the Application

Start the server by running:

go run main.go

The server will start on http://localhost:8081.

5. Connect to the Chat

To join the chat, open multiple browser tabs (or WebSocket clients) and connect to:

ws://localhost:8081/chat/username

Replace username with a unique name for each user. Messages sent by one user will be received by all other connected users.

Reference Screenshots

Initiate chat

Initiate chat

User 1

user1

User 2

user2

User 3

user3