This project demonstrates the use of Go's concurrency features to route data to a Redis database using tickers. Two goroutines (G1 and G2) continuously send evenly spaced ticks one second apart. Whenever G1 has passed 3 ticks, it writes data to the Redis database. Whenever G2 has passed 7 ticks, it alerts G1 to send data to the Redis database. This project utilizes Go channels for synchronization and communication between the goroutines.
- Concurrency: Utilize Go's goroutines and channels for concurrent execution and synchronization.
- Redis Integration: Interact with a Redis database to store tick data.
- Time-Based Operations: Implement tickers to trigger periodic actions.
- Docker: Use Docker to run Redis locally for a consistent development environment.
- Go 1.16 or later
- Docker
-
Clone the Repository:
git clone https://github.com/GJS2162/Go-ticker.git cd go-ticker-redis
-
Run Redis Locally via Docker:
docker run --name redis -p 6379:6379 -d redis
-
Install Go Redis Package:
go get github.com/go-redis/redis/v8
-
Compile and Run:
go run main.go
-
Observe the Output: The application will print data written to Redis in the console, indicating successful writes triggered by the tickers.
-
Access the Redis CLI:
docker exec -it redis redis-cli
-
List All Keys:
KEYS *
-
Get Value of a Specific Key:
GET <key>
Replace
<key>
with the actual key returned by theKEYS *
command. The key will contain information such as the source (G1 or G2), tick count, and timestamp. -
Example:
GET G1-2024-06-28T12:34:56Z
This command will return the data written by G1 at the specified timestamp.
This project showcases how to effectively use Go's concurrency features and integrate with a Redis database, providing a foundation for building more complex and scalable applications. By using Docker to manage Redis, it ensures a consistent and reliable development environment.