简体   繁体   中英

Spring Boot RedisTemplate equevalent of incr method

I used to use Jedis to increment long value in the following way:

Jedis jedis = new Jedis();
long key  = jedis.incr("myKey:");

Now I'm migrating my project to spring boot, and will use sprint boot RedisTemplate. However, I couln't find strict equevalent of the incr method in RedisTemplate. There is one following piece of code, but it's not the same

@Autowired
private RedisTemplate<String, Object> redisTemplate;

ValueOperations<String, Object> ops = redisTemplate.opsForValue();
ops.increment("myKey:", 1);

Is there an exact equevalent of this method ?

Thakns

There is not exact equivalent of the jedis.incr() method. But what you got is the right one to use. In the backend, it uses incrby() method which basically works same as incr() but instead of increment by 1, the increment is by the parameter value. So it is redundant to provide two different methods while you can get the same functionality from one.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM