https://github.com/thesaltree/redis-chat-app
Building a Real-Time Chat App in Go with Redis Pub/Sub and WebSockets
https://github.com/thesaltree/redis-chat-app
go-redis golang pub-sub real-time-chat redis websocket
Last synced: 2 months ago
JSON representation
Building a Real-Time Chat App in Go with Redis Pub/Sub and WebSockets
- Host: GitHub
- URL: https://github.com/thesaltree/redis-chat-app
- Owner: thesaltree
- Created: 2024-11-12T09:10:01.000Z (6 months ago)
- Default Branch: main
- Last Pushed: 2024-11-12T09:28:42.000Z (6 months ago)
- Last Synced: 2025-01-20T15:18:20.158Z (4 months ago)
- Topics: go-redis, golang, pub-sub, real-time-chat, redis, websocket
- Language: Go
- Homepage:
- Size: 5.86 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# 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](https://golang.org/dl/) (version 1.16 or later)
- [Redis](https://redis.io/download) server (running on `localhost:6379` by default)## Getting Started
### 1. Clone the Repository
```bash
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:```bash
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:```bash
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:```bash
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
User 1
User 2
User 3