RedisTemplate 操作 Long 类型值
问题描述
使用 RedisTemplate 存入 redis 的 Long 数据,在读取时,会提示类型错误,无法将 Integer 转换成 Long。
解决方法
使用 Object 进行接收,然后根据类型再将其转换成 Long
Long userId = null;
if (userIdObj instanceof Integer) {
userId = ((Integer) userIdObj).longValue();
} else if (userIdObj instanceof Long) {
userId = (Long) userIdObj;
}