An open API service indexing awesome lists of open source software.

https://github.com/jonathan-foucher/spring-boot-redis-lock-example

An example of managing resource lock with a redis
https://github.com/jonathan-foucher/spring-boot-redis-lock-example

java redis-lock spring-boot valkey

Last synced: 6 months ago
JSON representation

An example of managing resource lock with a redis

Awesome Lists containing this project

README

          

## Introduction
This project is an example of Redis / Valkey lock implementation with Spring Boot.

The objective is to create a resource lock on some database entities to prevent them being updated simultaneously by multiple processes.

## Run the project
### Valkey
Valkey is a free open-source project forked from Redis.
If you prefer, you can choose to run Redis instead.

You will need to launch a Valkey instance on your computer before running the project.

You can either install Valkey directly on your machine or run it through Docker :
```
docker run -p 6379:6379 valkey/valkey
```

### Database
Install postgres locally or run it through docker with :
```
docker run -p 5432:5432 -e POSTGRES_DB=redis_lock_db -e POSTGRES_USER=redis_lock -e POSTGRES_PASSWORD=redis_lock postgres
```

### Application
Once Valkey and the postgres database are launched, you can start the Spring Boot project and try it out.

Get all jobs
```
curl --location 'http://localhost:8080/redis-lock-example/jobs'
```

Create a job
```
curl --location --request POST 'http://localhost:8080/redis-lock-example/jobs?name=SOME_JOB'
```

Start a job
```
curl --location --request POST 'http://localhost:8080/redis-lock-example/jobs/3/start'
```