Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Redis Synchronization Example

This project demonstrates how to interact with a Redis instance using Java to store and retrieve a timestamp (lastSync). The project includes a Docker Compose setup to run a Redis instance with persistent storage, along with a Java program that retrieves and updates the lastSync timestamp.

Project Structure

  • docker-compose.yml: A Docker Compose configuration to spin up a Redis container with persistent storage.
  • Main.java: A Java program that connects to the Redis container, retrieves the lastSync key, simulates some work, and updates the lastSync key with the current timestamp.

Requirements

  • Docker Compose (2.33.0)
  • Java (JDK 11 or higher)
  • Redis

Setup

Running the Java Program

To run the Java program, follow these steps:

  1. Clone or download this repository.

    git clone git@gitlab.com:deroosean/helloredis.git
    cd helloredis
  2. Start Redis with Docker Compose

    docker-compose up
  3. Compile and run the Java program (Main.java) using your preferred IDE or the command line.

  4. The program will:

    • Retrieve the lastSync timestamp from Redis.
    • Simulate some work (by sleeping for 5 seconds).
    • Update the lastSync timestamp in Redis with the current time.
  5. Checking the Last Sync Key You can verify that the lastSync key is correctly set and updated by using the following command:

    docker exec -it redis-instance redis-cli GET lastSync

    This will show you the current value of the lastSync key stored in Redis.

Example Output

When you run the Java program, it will print the following to the console:

Last sync happened on: 2025-03-12T14:04:24.232473
Setting new last sync to: 2025-03-12T14:05:29.123456

Key Concepts

  • Redis: A fast, in-memory key-value store that is used for storing and retrieving data.
  • Jedis: A Java client for Redis that allows easy interaction with Redis from Java applications.

Releases

Packages

Contributors

Languages