是写一些 constant 类,用 public final static String 变量存 key 命名的固定部分?
譬如 read_book_by_user:user_id:3423211 那么
public class RedisKeyConstants{
public final static String READ_BOOK_BY_USER = "read_book_by_user:user_id:";
}
用的时候
redisTemplate.opsForValue.get(READ_BOOK_BY_USER+user.getId());
这样是比较好的普遍做法吗?
目前我是这样做的.