Set Cache Redis Expiration to 1 year

送分小仙女□ 提交于 2021-02-07 14:35:44

问题


How to set Redis Cache expiration to 1 year?

I tried to set the long value on the xml configuration to : 31556952000 (1 year), but then it caught an exception that type Integer doesn't recognize the value as Integer. I tried to search at Google, and it says that Integer maximum value is up to 2147483647, which means, if I set to that maximum value, I only get my cache expires on 24 days.

Here is my applicationContext.xml (I omitted unnecessary code) :

    ...
    <cache:annotation-driven />

    <bean id="redisCacheMap" class="java.util.HashMap">
        <constructor-arg index="0" type="java.util.Map">
            <map key-type="java.lang.String" value-type="java.lang.Integer">
                <entry key="ruleCache" value="86400"/>
            </map>
        </constructor-arg>
    </bean>
    ...

The code above is configured to set the expiration of ruleCache to only 1 day (86400 in ms).

Is it possible to do that? Thanks.


回答1:


Redis accepts integer value (maximum is up to 2 147 483 647) for expire command. The unit is second, not ms, so 1 year is 31556952 instead of 31556952000, and it fits into integer.

If you want your map to access Long, maybe you can adapt your config:

<map key-type="java.lang.String" value-type="java.lang.Long">


来源:https://stackoverflow.com/questions/28085785/set-cache-redis-expiration-to-1-year

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!