{"id":26452008,"url":"https://github.com/amul-thantharate/redisocketdb","last_synced_at":"2026-04-10T12:04:25.437Z","repository":{"id":282934252,"uuid":"950145460","full_name":"Amul-Thantharate/RediSocketDB","owner":"Amul-Thantharate","description":"This project demonstrates a real-time messaging system using Redis's Publish/Subscribe (Pub/Sub) feature, WebSocket for client communication, and MySQL for persistent message storage.","archived":false,"fork":false,"pushed_at":"2025-03-17T17:47:37.000Z","size":9,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-17T18:45:16.056Z","etag":null,"topics":["api","docker","docker-compose","golang","mysql","redis","webso"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Amul-Thantharate.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2025-03-17T17:44:56.000Z","updated_at":"2025-03-17T17:47:41.000Z","dependencies_parsed_at":"2025-03-17T18:47:32.879Z","dependency_job_id":"33776878-832d-4c97-8a57-8258e712f419","html_url":"https://github.com/Amul-Thantharate/RediSocketDB","commit_stats":null,"previous_names":["amul-thantharate/redisocketdb"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Amul-Thantharate%2FRediSocketDB","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Amul-Thantharate%2FRediSocketDB/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Amul-Thantharate%2FRediSocketDB/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Amul-Thantharate%2FRediSocketDB/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Amul-Thantharate","download_url":"https://codeload.github.com/Amul-Thantharate/RediSocketDB/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244267664,"owners_count":20425877,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["api","docker","docker-compose","golang","mysql","redis","webso"],"created_at":"2025-03-18T17:25:48.343Z","updated_at":"2025-12-31T00:15:49.154Z","avatar_url":"https://github.com/Amul-Thantharate.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# 📢 Redis Pub/Sub with WebSocket and MySQL Persistence\n\nThis project demonstrates a real-time messaging system using Redis's Publish/Subscribe (Pub/Sub) feature, WebSocket for client communication, and MySQL for persistent message storage.\n\n## 🚀 Features\n\n* **Real-time Messaging:** Users can publish and subscribe to channels to receive messages in real-time.\n* **WebSocket Communication:** Uses WebSockets for efficient, bidirectional communication between the server and clients.\n* **Redis Pub/Sub:** Leverages Redis's Pub/Sub mechanism for message broadcasting.\n* **MySQL Persistence:** Stores all messages in a MySQL database for historical access.\n* **Graceful Shutdown:** The server can be shut down gracefully with `Ctrl+C` or `SIGTERM`.\n* **Multiple Channel Subscriptions:** Clients can subscribe to multiple channels simultaneously.\n\n\n## 🛠️ Technologies Used\n\n* **Go:** The programming language for the backend server.\n* **Redis:** In-memory data structure store used for Pub/Sub.\n* **MySQL:** Relational database for persistent message storage.\n* **Gorilla WebSocket:** Go library for WebSocket implementation.\n* **go-redis:** Go client for interacting with Redis.\n* **GORM:** ORM library for interacting with MySQL.\n\n## ⚙️ Setup and Installation\n\n1. **Prerequisites:**\n    * Go (latest stable version recommended)\n    * Docker (for running Redis) (Recommended)\n    * Redis server (running on `localhost:6379` by default) \n    * MySQL server (running on `localhost:3306` with a `chatdb` database)\n    * Postman Or Any api client for testing Api\n\n\n2.**Docker For Redis and Mysql:**\n```bash \n    docker run -d --name redis-stack -p 6379:6379 -p 8001:8001 redis/redis-stack (Redis Setup)\n    docker run -d --name mysql_chat \\\n        -e MYSQL_ROOT_PASSWORD=rootpassword \\\n        -e MYSQL_DATABASE=chatdb \\\n        -e MYSQL_USER=chatuser \\\n        -e MYSQL_PASSWORD=chatpassword \\\n        -p 3306:3306 \\\n        --restart always \\\n    mysql:latest\n```\n\n\n3. **Clone the Repository:**\n    ```bash\n    git clone https://github.com/Amul-Thantharate/RediSocketDB.git\n    cd RediSocketDB\n    ```\n\n4. **Database Setup:**\n    * Create a database named `chatdb` in your MySQL server.\n    * The application will automatically create the `messages` table when it starts.\n    * Make sure you have a user `nora` with password `root` with access to the `chatdb` database.  You can change this in the `main.go` file.\n\n5. **Install Dependencies:**\n    ```bash\n    go mod tidy\n    ```\n\n6. **Run the Application:**\n    ```bash\n    go run main.go\n    ```\n    You should see the message `Starting server on :8080` in your terminal.\n\n## 🕹️ Usage\n\n### Publishing Messages\n\n* **Endpoint:** `POST /publish`\n* **Parameters:**\n    * `channel`: The channel to publish the message to.\n    * `message`: The message content.\n* **Example (using `curl`):**\n    ```bash\n    curl -X POST -d \"channel=general\u0026message=Hello, world!\" http://localhost:8080/publish\n    ```\n    This will publish \"Hello, world!\" to the \"general\" channel and store it in MySQL.\n\n### Subscribing to Messages\n\n* **Endpoint:** `/subscribe`\n* **Query Parameters:**\n    * `channel`: One or more channels to subscribe to (e.g., `/subscribe?channel=general\u0026channel=news`).\n* **Example (using a WebSocket client):**\n    * Connect to `ws://localhost:8080/subscribe?channel=general\u0026channel=news`  (to subscribe to both \"general\" and \"news\" channels).\n    * You will receive messages from both channels in real-time.\n* **Example (using a browser):** You can use a browser extension like \"Simple WebSocket Client\" to connect to the websocket.\n\n\n## 🛑 Stopping the Server\n\n* Press `Ctrl+C` in the terminal where the server is running.\n* The server will shut down gracefully, closing the Redis and MySQL connections.\n\n\n## Troubleshooting\n\n* **Database Connection Errors:** Ensure your MySQL server is running, the database `chatdb` exists, and the user `nora` has the correct permissions. Check the MySQL connection string in `main.go`.\n* **Redis Connection Errors:** Make sure your Redis server is running on the specified address and port (`localhost:6379`).\n\n## Contributing 🤝\n\nWe welcome contributions!  Please follow these steps:\n\n1. Fork the repository.\n2. Create a new branch (`git checkout -b feature/your-feature`).\n3. Make your changes and commit them (`git commit -m \"Your commit message\"`).\n4. Push your branch to your fork (`git push origin feature/your-feature`).\n5. Open a pull request.\n\n\n## License 📄\n\nThis project is licensed under the Apache License 2.0.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Famul-thantharate%2Fredisocketdb","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Famul-thantharate%2Fredisocketdb","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Famul-thantharate%2Fredisocketdb/lists"}