I need to create a counter in Redis, by default the method .incrBy()
creates the counter with 0, but I need to start it with 123.
Do not want to handle it in my java code, how can I do it on Redis side? In transaction?
I need to create a counter in Redis, by default the method .incrBy()
creates the counter with 0, but I need to start it with 123.
Do not want to handle it in my java code, how can I do it on Redis side? In transaction?
2
Answers
I am not sure whether I get it right(please comment if not) but INCRBY takes second argument to set the counter to the given value for non existing keys.
If the key exist, then increments the value of the existing.