opsForValue() 的 set 用法

void set(K var1, V var2, long var3, TimeUnit var5);//opsForValue()中 set 用法 
redisTemplate.opsForValue().set(REDIS_KEY_PREFIX_ + key, hotelSubList, 5L, TimeUnit.MINUTES);

var1:key

var2:value

var3:是后面时间的倍数

var5:时间单位

比如下面的那个例子,表示缓存 5 分钟,后面的 var5 可以把分钟换算成各种单位,如秒,微妙。。。,源码如下:

/**
     * Time unit representing sixty seconds
     */
    MINUTES {
        public long toNanos(long d)   { return x(d, C4/C0, MAX/(C4/C0)); }
        public long toMicros(long d)  { return x(d, C4/C1, MAX/(C4/C1)); }
        public long toMillis(long d)  { return x(d, C4/C2, MAX/(C4/C2)); }
        public long toSeconds(long d) { return x(d, C4/C3, MAX/(C4/C3)); }
        public long toMinutes(long d) { return d; }
        public long toHours(long d)   { return d/(C5/C4); }
        public long toDays(long d)    { return d/(C6/C4); }
        public long convert(long d, TimeUnit u) { return u.toMinutes(d); }
        int excessNanos(long d, long m) { return 0; }
    },

 

你可能感兴趣的:(Java)