项目需求,需要获取不同的自增数,然后与其他信息拼接成一个字符串作为编号,这边有一种基于数据库的获取自增数的方法,这边略过,还有一种基于redis的实现。

此方法可以用到redis的自增函数

 

public long getUniqueNum() {
        String key = "unique_num";
        Jedis jedisInstance = redisManager.getJedis();
        long count;
        if (jedisInstance.get(key) == null) {
            //这边根据项目逻辑赋值一下初值
        } else {
            //获取加1后的值
            count = jedisInstance.incr(key).longValue();
        }
        jedisInstance.close();
        return count;
    }

 

相关文章:

  • 2022-12-23
  • 2022-03-09
  • 2021-11-18
  • 2021-06-08
  • 2021-10-12
猜你喜欢
  • 2019-09-27
  • 2022-12-23
  • 2022-02-28
  • 2022-12-23
  • 2021-10-20
相关资源
相似解决方案