String redisKey =
“user_lock_menu_total_count_” + paramsDto.getUserId() + “_” + paramsDto.getMenuId();
BoundValueOperations<String, String> returnKey = stringRedisTemplate.boundValueOps(redisKey);
// 判断key是否有对应的value,如果有,则返回false,如果没有,添加,返回true
if (!returnKey.setIfAbsent(REPEAT_OPERATE)) {
throw new JshServerException(JshI18nUtil.getMsg(“sys.permission.update.menu.count.repeat”));
} else {
returnKey.expire(1, TimeUnit.SECONDS); // 设置过期时间
}
//处理业务逻辑
// 操作完成,释放redis
stringRedisTemplate.delete(redisKey);