Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RedisAtomicInteger remove existing key when a value for initialValue is provided [DATAREDIS-1080] #1652

spring-projects-issues opened this issue Dec 20, 2019 · 1 comment
type: bug type: documentation


Copy link

spring-projects-issues commented Dec 20, 2019

ERNESTO ARROYO opened DATAREDIS-1080 and commented

In the documentation && javaDoc, Spring Data Redis says that a RedisAtomicInteger has this constructor:

  * Constructs a new \{@link RedisAtomicInteger} instance.
  * @param redisCounter Redis key of this counter.
  * @param factory connection factory.
  * @param initialValue initial value to set if the Redis key is absent.

public RedisAtomicInteger(String redisCounter, 
                          RedisConnectionFactory factory, 
                           int initialValue) {  
    this(redisCounter, factory, Integer.valueOf(initialValue));

So we use this constructor expecting to keep the key (because if exists) but our app is removing it on every start:

new RedisAtomicInteger("KEY", redisConnFactoty, 0)

it ALWAYS set to zero, it doesn't matter that "KEY" exists or not.

The source code of the constructor for RedisAtomicInteger has this:
if (initialValue == null) }
  else {

So, as my initialValue is not null, it will set to '0' in any case

I think this is a bug in code, or a mistake in documentation...

Am I right?

Affects: 2.2.3 (Moore SR3)

Backported to: 2.2.5 (Moore SR5), 2.1.16 (Lovelace SR16)

Copy link

spring-projects-issues commented Feb 13, 2020

Mark Paluch commented

Good catch, we need to fix our documentation. The idea is, if you provide an initial value, then the value will be set regardless of whether the key already exists

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
type: bug type: documentation
None yet

No branches or pull requests

2 participants