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.
- 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.
git clone https://github.com/yourusername/redis-chat-app.git
cd redis-chat-app
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
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.
Start the server by running:
go run main.go
The server will start on http://localhost:8081.
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.
Initiate chat
User 1
User 2
User 3