This project should demonstrate an error which occurs when performing concurrent read and write redis operations.
I looks like Spring or Redis or something in between can't read values while they are written by CrudRepository
.
The application behaves as if the value did not exist.
Simply clone this git repository and run tests.
For example by running
mvn test
There two test classes and each one has two test methods:
RepositoryControllerTest
Using aCrudRepsoitory
:ExampleRepository
getWithoutIncreasingReadCounter
Creates one entry in redis and reads it 100 times concurrently.
This is working well.getAndIncreaseReadCounter
Creates one entry in redis and reads it 100 times concurrently. For each request the value is modified and written back to redis.
This is not working!
TemplateControllerTest
Using aRedisTemplate
:TemplateExampleRepository
getWithoutIncreasingReadCounter
Creates one entry in redis and reads it 100 times concurrently.
This is working well.getAndIncreaseReadCounter
Creates one entry in redis and reads it 100 times concurrently. For each request the value is modified and written back to redis.
This is working well.
CrudRepository |
RedisTemplate |
|
---|---|---|
read 100 times concurrently: | working | working |
read and write 100 times concurrently: | NOT working | working |