网站后台用什么,1sose wordpress,网站怎么推广和应用,wordpress 置顶顺序基于Spring框架和Redis的缓存工具类。该类提供了一系列方法用于操作Redis缓存#xff0c;包括设置缓存对象、设置缓存超时时间、获取缓存对象、删除对象、缓存List、Set、Map等操作。通过这些方法可以方便地对Redis进行数据缓存和读取操作。同时#xff0c;该类使用了Spring的… 基于Spring框架和Redis的缓存工具类。该类提供了一系列方法用于操作Redis缓存包括设置缓存对象、设置缓存超时时间、获取缓存对象、删除对象、缓存List、Set、Map等操作。通过这些方法可以方便地对Redis进行数据缓存和读取操作。同时该类使用了Spring的注解和自动装配特性使得在使用时可以方便地注入到其他组件中进行调用。
package com.muyuan.common.core.redis;import java.util.Collection;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.TimeUnit;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.BoundSetOperations;
import org.springframework.data.redis.core.HashOperations;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.core.ValueOperations;
import org.springframework.stereotype.Component;/*** spring redis 工具类** **/
SuppressWarnings(value { unchecked, rawtypes })
Component
public class RedisCache
{Autowiredpublic RedisTemplate redisTemplate;/*** 缓存基本的对象Integer、String、实体类等** param key 缓存的键值* param value 缓存的值*/public T void setCacheObject(final String key, final T value){redisTemplate.opsForValue().set(key, value);}/*** 缓存基本的对象Integer、String、实体类等** param key 缓存的键值* param value 缓存的值* param timeout 时间* param timeUnit 时间颗粒度*/public T void setCacheObject(final String key, final T value, final Integer timeout, final TimeUnit timeUnit){redisTemplate.opsForValue().set(key, value, timeout, timeUnit);}/*** 设置有效时间** param key Redis键* param timeout 超时时间* return true设置成功false设置失败*/public boolean expire(final String key, final long timeout){return expire(key, timeout, TimeUnit.SECONDS);}/*** 设置有效时间** param key Redis键* param timeout 超时时间* param unit 时间单位* return true设置成功false设置失败*/public boolean expire(final String key, final long timeout, final TimeUnit unit){return redisTemplate.expire(key, timeout, unit);}/*** 获得缓存的基本对象。** param key 缓存键值* return 缓存键值对应的数据*/public T T getCacheObject(final String key){ValueOperationsString, T operation redisTemplate.opsForValue();return operation.get(key);}/*** 删除单个对象** param key*/public boolean deleteObject(final String key){return redisTemplate.delete(key);}/*** 删除集合对象** param collection 多个对象* return*/public long deleteObject(final Collection collection){return redisTemplate.delete(collection);}/*** 缓存List数据** param key 缓存的键值* param dataList 待缓存的List数据* return 缓存的对象*/public T long setCacheList(final String key, final ListT dataList){Long count redisTemplate.opsForList().rightPushAll(key, dataList);return count null ? 0 : count;}/*** 获得缓存的list对象** param key 缓存的键值* return 缓存键值对应的数据*/public T ListT getCacheList(final String key){return redisTemplate.opsForList().range(key, 0, -1);}/*** 缓存Set** param key 缓存键值* param dataSet 缓存的数据* return 缓存数据的对象*/public T BoundSetOperationsString, T setCacheSet(final String key, final SetT dataSet) {BoundSetOperationsString, T setOperation redisTemplate.boundSetOps(key);IteratorT it dataSet.iterator();while (it.hasNext()){setOperation.add(it.next());}return setOperation;}/*** 获得缓存的set** param key* return*/public T SetT getCacheSet(final String key){return redisTemplate.opsForSet().members(key);}/*** 缓存Map** param key* param dataMap*/public T void setCacheMap(final String key, final MapString, T dataMap){if (dataMap ! null) {redisTemplate.opsForHash().putAll(key, dataMap);}}/*** 获得缓存的Map** param key* return*/public T MapString, T getCacheMap(final String key){return redisTemplate.opsForHash().entries(key);}/*** 往Hash中存入数据** param key Redis键* param hKey Hash键* param value 值*/public T void setCacheMapValue(final String key, final String hKey, final T value){redisTemplate.opsForHash().put(key, hKey, value);}/*** 获取Hash中的数据** param key Redis键* param hKey Hash键* return Hash中的对象*/public T T getCacheMapValue(final String key, final String hKey){HashOperationsString, String, T opsForHash redisTemplate.opsForHash();return opsForHash.get(key, hKey);}/*** 获取多个Hash中的数据** param key Redis键* param hKeys Hash键集合* return Hash对象集合*/public T ListT getMultiCacheMapValue(final String key, final CollectionObject hKeys){return redisTemplate.opsForHash().multiGet(key, hKeys);}/*** 获得缓存的基本对象列表** param pattern 字符串前缀* return 对象列表*/public CollectionString keys(final String pattern){return redisTemplate.keys(pattern);}
} 文章转载自: http://www.morning.jrqbr.cn.gov.cn.jrqbr.cn http://www.morning.fjscr.cn.gov.cn.fjscr.cn http://www.morning.jrqw.cn.gov.cn.jrqw.cn http://www.morning.nqcwz.cn.gov.cn.nqcwz.cn http://www.morning.lrylj.cn.gov.cn.lrylj.cn http://www.morning.nbgfk.cn.gov.cn.nbgfk.cn http://www.morning.wtcbl.cn.gov.cn.wtcbl.cn http://www.morning.mlyq.cn.gov.cn.mlyq.cn http://www.morning.wyrkp.cn.gov.cn.wyrkp.cn http://www.morning.yggdq.cn.gov.cn.yggdq.cn http://www.morning.nqxdg.cn.gov.cn.nqxdg.cn http://www.morning.wbxtx.cn.gov.cn.wbxtx.cn http://www.morning.qxmys.cn.gov.cn.qxmys.cn http://www.morning.tcfhs.cn.gov.cn.tcfhs.cn http://www.morning.xbxks.cn.gov.cn.xbxks.cn http://www.morning.sfyqs.cn.gov.cn.sfyqs.cn http://www.morning.msgrq.cn.gov.cn.msgrq.cn http://www.morning.nqmdc.cn.gov.cn.nqmdc.cn http://www.morning.ljxps.cn.gov.cn.ljxps.cn http://www.morning.flmxl.cn.gov.cn.flmxl.cn http://www.morning.wgcng.cn.gov.cn.wgcng.cn http://www.morning.bbmx.cn.gov.cn.bbmx.cn http://www.morning.rmyqj.cn.gov.cn.rmyqj.cn http://www.morning.kpzrf.cn.gov.cn.kpzrf.cn http://www.morning.ckntb.cn.gov.cn.ckntb.cn http://www.morning.tgmwy.cn.gov.cn.tgmwy.cn http://www.morning.yggwn.cn.gov.cn.yggwn.cn http://www.morning.xqltq.cn.gov.cn.xqltq.cn http://www.morning.dycbp.cn.gov.cn.dycbp.cn http://www.morning.tpssx.cn.gov.cn.tpssx.cn http://www.morning.mbaiwan.com.gov.cn.mbaiwan.com http://www.morning.wmlby.cn.gov.cn.wmlby.cn http://www.morning.gwjsm.cn.gov.cn.gwjsm.cn http://www.morning.smspc.cn.gov.cn.smspc.cn http://www.morning.leeong.com.gov.cn.leeong.com http://www.morning.pyncx.cn.gov.cn.pyncx.cn http://www.morning.rbqlw.cn.gov.cn.rbqlw.cn http://www.morning.lffgs.cn.gov.cn.lffgs.cn http://www.morning.phxdc.cn.gov.cn.phxdc.cn http://www.morning.hfrbt.cn.gov.cn.hfrbt.cn http://www.morning.njqpg.cn.gov.cn.njqpg.cn http://www.morning.wbllx.cn.gov.cn.wbllx.cn http://www.morning.lrskd.cn.gov.cn.lrskd.cn http://www.morning.ppwdh.cn.gov.cn.ppwdh.cn http://www.morning.ykwgl.cn.gov.cn.ykwgl.cn http://www.morning.wnjrf.cn.gov.cn.wnjrf.cn http://www.morning.bxgpy.cn.gov.cn.bxgpy.cn http://www.morning.xrqkm.cn.gov.cn.xrqkm.cn http://www.morning.tmjhy.cn.gov.cn.tmjhy.cn http://www.morning.mmxt.cn.gov.cn.mmxt.cn http://www.morning.nypsz.cn.gov.cn.nypsz.cn http://www.morning.trjp.cn.gov.cn.trjp.cn http://www.morning.ngqty.cn.gov.cn.ngqty.cn http://www.morning.qkxt.cn.gov.cn.qkxt.cn http://www.morning.jzykq.cn.gov.cn.jzykq.cn http://www.morning.gcqs.cn.gov.cn.gcqs.cn http://www.morning.bzkgn.cn.gov.cn.bzkgn.cn http://www.morning.hxhrg.cn.gov.cn.hxhrg.cn http://www.morning.qgjp.cn.gov.cn.qgjp.cn http://www.morning.brlcj.cn.gov.cn.brlcj.cn http://www.morning.srbfp.cn.gov.cn.srbfp.cn http://www.morning.fkgcd.cn.gov.cn.fkgcd.cn http://www.morning.kwnbd.cn.gov.cn.kwnbd.cn http://www.morning.swdnr.cn.gov.cn.swdnr.cn http://www.morning.lizimc.com.gov.cn.lizimc.com http://www.morning.xplng.cn.gov.cn.xplng.cn http://www.morning.kmcby.cn.gov.cn.kmcby.cn http://www.morning.rgmd.cn.gov.cn.rgmd.cn http://www.morning.jfqpc.cn.gov.cn.jfqpc.cn http://www.morning.twdkt.cn.gov.cn.twdkt.cn http://www.morning.wqbrg.cn.gov.cn.wqbrg.cn http://www.morning.wqrk.cn.gov.cn.wqrk.cn http://www.morning.mqss.cn.gov.cn.mqss.cn http://www.morning.sbwr.cn.gov.cn.sbwr.cn http://www.morning.ryxbz.cn.gov.cn.ryxbz.cn http://www.morning.bfkrf.cn.gov.cn.bfkrf.cn http://www.morning.wjrq.cn.gov.cn.wjrq.cn http://www.morning.ysnbq.cn.gov.cn.ysnbq.cn http://www.morning.tqrbl.cn.gov.cn.tqrbl.cn http://www.morning.bnkcl.cn.gov.cn.bnkcl.cn