Coder Social home page Coder Social logo

go-ticker's Introduction

Concurrent Data Routing to Redis using Go Tickers

Project Overview

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.

Features

  • 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.

Requirements

  • Go 1.16 or later
  • Docker

Setup

  1. Clone the Repository:

    git clone https://github.com/GJS2162/Go-ticker.git
    cd go-ticker-redis
  2. Run Redis Locally via Docker:

    docker run --name redis -p 6379:6379 -d redis
  3. Install Go Redis Package:

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

Running the Application

  1. Compile and Run:

    go run main.go
  2. Observe the Output: The application will print data written to Redis in the console, indicating successful writes triggered by the tickers.

Checking Data in Redis

  1. Access the Redis CLI:

    docker exec -it redis redis-cli
  2. List All Keys:

    KEYS *
  3. Get Value of a Specific Key:

    GET <key>

    Replace <key> with the actual key returned by the KEYS * command. The key will contain information such as the source (G1 or G2), tick count, and timestamp.

  4. Example:

    GET G1-2024-06-28T12:34:56Z

    This command will return the data written by G1 at the specified timestamp.

Conclusion

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.

go-ticker's People

Contributors

gjs2162 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.