Member-only story

Redis prevents duplicate commits

Beck Moulton
5 min readMar 31, 2023

--

#1 Requirements Analysis

In the process of web application development, we often encounter the problem of repeated submission of forms. If users submit forms multiple times in a short period of time, it may cause problems such as repeated insertion of data into the database and repeated sending of emails, which seriously affect the stability and correctness of the system. Therefore, some way is needed to prevent repeated submission of forms.

This solution aims to provide a Token-based form repeated submission solution, generate a unique Token at the server level and add it to the form in the form of hidden fields on the front-end page, and verify whether the Token submitted by the Client is valid. In this way, the problem of repeated form submission can be effectively avoided.

#2. Technology Implementation

This solution is developed using Spring Boot framework and uses Redis to store Token. The specific implementation steps are as follows:

2.1 Backend implementation

First, we need to create a controller class called TokenController that handles requests to get form tokens. For example:

import org.springframework.beans.factory.annotation.Autowired;
import…

--

--

Beck Moulton
Beck Moulton

Written by Beck Moulton

Focus on the back-end field, do actual combat technology sharing Buy me a Coffee if You Appreciate My Hard Work https://www.buymeacoffee.com/BeckMoulton

No responses yet