<output id="qn6qe"></output>

    1. <output id="qn6qe"><tt id="qn6qe"></tt></output>
    2. <strike id="qn6qe"></strike>

      亚洲 日本 欧洲 欧美 视频,日韩中文字幕有码av,一本一道av中文字幕无码,国产线播放免费人成视频播放,人妻少妇偷人无码视频,日夜啪啪一区二区三区,国产尤物精品自在拍视频首页,久热这里只有精品12

      SpringBoot 使用RedisTemplate操作Redis

      新版:

      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.HashOperations;
      import org.springframework.data.redis.core.ListOperations;
      import org.springframework.data.redis.core.RedisTemplate;
      import org.springframework.data.redis.core.SetOperations;
      import org.springframework.data.redis.core.ValueOperations;
      import org.springframework.data.redis.core.ZSetOperations;
      import org.springframework.stereotype.Component;
      import org.springframework.util.CollectionUtils;
      
      @Component
      public class RedisUtil {
      
          @Autowired
          private RedisTemplate<String, Object> redisTemplate;
          @Autowired
          private ValueOperations<String, String> valueOperations;
          @Autowired
          private HashOperations<String, String, Object> hashOperations;
          @Autowired
          private ListOperations<String, Object> listOperations;
          @Autowired
          private SetOperations<String, Object> setOperations;
          @Autowired
          private ZSetOperations<String, Object> zSetOperations;
      
          //=============================common============================
          /**
           * 指定緩存失效時間
           * @param key 鍵
           * @param time 時間(秒)
           * @return
           */
          public boolean expire(String key,long time){
              try {
                  if(time>0){
                      redisTemplate.expire(key, time, TimeUnit.SECONDS);
                  }
                  return true;
              } catch (Exception e) {
                  e.printStackTrace();
                  return false;
              }
          }
      
          /**
           * 根據key 獲取過期時間
           * @param key 鍵 不能為null
           * @return 時間(秒) 返回0代表為永久有效
           */
          public long getExpire(String key){
              return redisTemplate.getExpire(key,TimeUnit.SECONDS);
          }
      
          /**
           * 判斷key是否存在
           * @param key 鍵
           * @return true 存在 false不存在
           */
          public boolean hasKey(String key){
              try {
                  return redisTemplate.hasKey(key);
              } catch (Exception e) {
                  e.printStackTrace();
                  return false;
              }
          }
      
          /**
           * 刪除緩存
           * @param key 可以傳一個值 或多個
           */
          @SuppressWarnings("unchecked")
          public void del(String ... key){
              if(key!=null&&key.length>0){
                  if(key.length==1){
                      redisTemplate.delete(key[0]);
                  }else{
                      redisTemplate.delete(CollectionUtils.arrayToList(key));
                  }
              }
          }
      
          //============================String=============================
          /**
           * 普通緩存獲取
           * @param key 鍵
           * @return 值
           */
          public Object get(String key){
              return key==null?null:valueOperations.get(key);
          }
      
          /**
           * 普通緩存放入
           * @param key 鍵
           * @param value 值
           * @return true成功 false失敗
           */
          public boolean set(String key,Object value) {
              try {
                  valueOperations.set(key, value);
                  return true;
              } catch (Exception e) {
                  e.printStackTrace();
                  return false;
              }
      
          }
      
          /**
           * 普通緩存放入并設置時間
           * @param key 鍵
           * @param value 值
           * @param time 時間(秒) time要大于0 如果time小于等于0 將設置無限期
           * @return true成功 false 失敗
           */
          public boolean set(String key,Object value,long time){
              try {
                  if(time>0){
                      valueOperations.set(key, value, time, TimeUnit.SECONDS);
                  }else{
                      set(key, value);
                  }
                  return true;
              } catch (Exception e) {
                  e.printStackTrace();
                  return false;
              }
          }
      
          /**
           * 遞增
           * @param key 鍵
           * @param by 要增加幾(大于0)
           * @return
           */
          public long incr(String key, long delta){
              if(delta<0){
                  throw new RuntimeException("遞增因子必須大于0");
              }
              return valueOperations.increment(key, delta);
          }
      
          /**
           * 遞減
           * @param key 鍵
           * @param by 要減少幾(小于0)
           * @return
           */
          public long decr(String key, long delta){
              if(delta<0){
                  throw new RuntimeException("遞減因子必須大于0");
              }
              return valueOperations.increment(key, -delta);
          }
      
          //================================Map=================================
          /**
           * HashGet
           * @param key 鍵 不能為null
           * @param item 項 不能為null
           * @return 值
           */
          public Object hget(String key,String item){
              return hashOperations.get(key, item);
          }
      
          /**
           * 獲取hashKey對應的所有鍵值
           * @param key 鍵
           * @return 對應的多個鍵值
           */
          public Map<Object,Object> hmget(String key){
              return hashOperations.entries(key);
          }
      
          /**
           * HashSet
           * @param key 鍵
           * @param map 對應多個鍵值
           * @return true 成功 false 失敗
           */
          public boolean hmset(String key, Map<String,Object> map){
              try {
                  hashOperations.putAll(key, map);
                  return true;
              } catch (Exception e) {
                  e.printStackTrace();
                  return false;
              }
          }
      
          /**
           * HashSet 并設置時間
           * @param key 鍵
           * @param map 對應多個鍵值
           * @param time 時間(秒)
           * @return true成功 false失敗
           */
          public boolean hmset(String key, Map<String,Object> map, long time){
              try {
                  hashOperations.putAll(key, map);
                  if(time>0){
                      expire(key, time);
                  }
                  return true;
              } catch (Exception e) {
                  e.printStackTrace();
                  return false;
              }
          }
      
          /**
           * 向一張hash表中放入數據,如果不存在將創建
           * @param key 鍵
           * @param item 項
           * @param value 值
           * @return true 成功 false失敗
           */
          public boolean hset(String key,String item,Object value) {
              try {
                  hashOperations.put(key, item, value);
                  return true;
              } catch (Exception e) {
                  e.printStackTrace();
                  return false;
              }
          }
      
          /**
           * 向一張hash表中放入數據,如果不存在將創建
           * @param key 鍵
           * @param item 項
           * @param value 值
           * @param time 時間(秒)  注意:如果已存在的hash表有時間,這里將會替換原有的時間
           * @return true 成功 false失敗
           */
          public boolean hset(String key,String item,Object value,long time) {
              try {
                  hashOperations.put(key, item, value);
                  if(time>0){
                      expire(key, time);
                  }
                  return true;
              } catch (Exception e) {
                  e.printStackTrace();
                  return false;
              }
          }
      
          /**
           * 刪除hash表中的值
           * @param key 鍵 不能為null
           * @param item 項 可以使多個 不能為null
           */
          public void hdel(String key, Object... item){
              hashOperations.delete(key,item);
          }
      
          /**
           * 判斷hash表中是否有該項的值
           * @param key 鍵 不能為null
           * @param item 項 不能為null
           * @return true 存在 false不存在
           */
          public boolean hHasKey(String key, String item){
              return hashOperations.hasKey(key, item);
          }
      
          /**
           * hash遞增 如果不存在,就會創建一個 并把新增后的值返回
           * @param key 鍵
           * @param item 項
           * @param by 要增加幾(大于0)
           * @return
           */
          public double hincr(String key, String item,double by){
              return hashOperations.increment(key, item, by);
          }
      
          /**
           * hash遞減
           * @param key 鍵
           * @param item 項
           * @param by 要減少記(小于0)
           * @return
           */
          public double hdecr(String key, String item,double by){
              return hashOperations.increment(key, item,-by);
          }
      
          //============================set=============================
          /**
           * 根據key獲取Set中的所有值
           * @param key 鍵
           * @return
           */
          public Set<Object> sGet(String key){
              try {
                  return setOperations.members(key);
              } catch (Exception e) {
                  e.printStackTrace();
                  return null;
              }
          }
      
          /**
           * 根據value從一個set中查詢,是否存在
           * @param key 鍵
           * @param value 值
           * @return true 存在 false不存在
           */
          public boolean sHasKey(String key,Object value){
              try {
                  return setOperations.isMember(key, value);
              } catch (Exception e) {
                  e.printStackTrace();
                  return false;
              }
          }
      
          /**
           * 將數據放入set緩存
           * @param key 鍵
           * @param values 值 可以是多個
           * @return 成功個數
           */
          public long sSet(String key, Object...values) {
              try {
                  return setOperations.add(key, values);
              } catch (Exception e) {
                  e.printStackTrace();
                  return 0;
              }
          }
      
          /**
           * 將set數據放入緩存
           * @param key 鍵
           * @param time 時間(秒)
           * @param values 值 可以是多個
           * @return 成功個數
           */
          public long sSetAndTime(String key,long time,Object...values) {
              try {
                  Long count = setOperations.add(key, values);
                  if(time>0) expire(key, time);
                  return count;
              } catch (Exception e) {
                  e.printStackTrace();
                  return 0;
              }
          }
      
          /**
           * 獲取set緩存的長度
           * @param key 鍵
           * @return
           */
          public long sGetSetSize(String key){
              try {
                  return setOperations.size(key);
              } catch (Exception e) {
                  e.printStackTrace();
                  return 0;
              }
          }
      
          /**
           * 移除值為value的
           * @param key 鍵
           * @param values 值 可以是多個
           * @return 移除的個數
           */
          public long setRemove(String key, Object ...values) {
              try {
                  Long count = setOperations.remove(key, values);
                  return count;
              } catch (Exception e) {
                  e.printStackTrace();
                  return 0;
              }
          }
          //===============================list=================================
      
          /**
           * 獲取list緩存的內容
           * @param key 鍵
           * @param start 開始
           * @param end 結束  0 到 -1代表所有值
           * @return
           */
          public List<Object> lGet(String key, long start, long end){
              try {
                  return listOperations.range(key, start, end);
              } catch (Exception e) {
                  e.printStackTrace();
                  return null;
              }
          }
      
          /**
           * 獲取list緩存的所有內容
           * @param key
           * @return
           */
          public List<Object> lGetAll(String key){
              return lGet(key,0,-1);
          }
      
          /**
           * 獲取list緩存的長度
           * @param key 鍵
           * @return
           */
          public long lGetListSize(String key){
              try {
                  return listOperations.size(key);
              } catch (Exception e) {
                  e.printStackTrace();
                  return 0;
              }
          }
      
          /**
           * 通過索引 獲取list中的值
           * @param key 鍵
           * @param index 索引  index>=0時, 0 表頭,1 第二個元素,依次類推;index<0時,-1,表尾,-2倒數第二個元素,依次類推
           * @return
           */
          public Object lGetIndex(String key,long index){
              try {
                  return listOperations.index(key, index);
              } catch (Exception e) {
                  e.printStackTrace();
                  return null;
              }
          }
      
          /**
           * 將list放入緩存
           * @param key 鍵
           * @param value 值
           * @param time 時間(秒)
           * @return
           */
          public boolean lSet(String key, Object value) {
              try {
                  listOperations.rightPush(key, value);
                  return true;
              } catch (Exception e) {
                  e.printStackTrace();
                  return false;
              }
          }
      
          /**
           * 將list放入緩存
           * @param key 鍵
           * @param value 值
           * @param time 時間(秒)
           * @return
           */
          public boolean lSet(String key, Object value, long time) {
              try {
                  listOperations.rightPush(key, value);
                  if (time > 0) expire(key, time);
                  return true;
              } catch (Exception e) {
                  e.printStackTrace();
                  return false;
              }
          }
      
          /**
           * 將list放入緩存
           * @param key 鍵
           * @param value 值
           * @param time 時間(秒)
           * @return
           */
          public boolean lSet(String key, List<Object> value) {
              try {
                  listOperations.rightPushAll(key, value);
                  return true;
              } catch (Exception e) {
                  e.printStackTrace();
                  return false;
              }
          }
      
          /**
           * 將list放入緩存
           * @param key 鍵
           * @param value 值
           * @param time 時間(秒)
           * @return
           */
          public boolean lSet(String key, List<Object> value, long time) {
              try {
                  listOperations.rightPushAll(key, value);
                  if (time > 0) expire(key, time);
                  return true;
              } catch (Exception e) {
                  e.printStackTrace();
                  return false;
              }
          }
      
          /**
           * 根據索引修改list中的某條數據
           * @param key 鍵
           * @param index 索引
           * @param value 值
           * @return
           */
          public boolean lUpdateIndex(String key, long index,Object value) {
              try {
                  listOperations.set(key, index, value);
                  return true;
              } catch (Exception e) {
                  e.printStackTrace();
                  return false;
              }
          }
      
          /**
           * 移除N個值為value
           * @param key 鍵
           * @param count 移除多少個
           * @param value 值
           * @return 移除的個數
           */
          public long lRemove(String key,long count,Object value) {
              try {
                  Long remove = listOperations.remove(key, count, value);
                  return remove;
              } catch (Exception e) {
                  e.printStackTrace();
                  return 0;
              }
          }
      }

      RedisConfig:

      import com.fasterxml.jackson.annotation.JsonAutoDetect;
      import com.fasterxml.jackson.annotation.PropertyAccessor;
      import com.fasterxml.jackson.databind.ObjectMapper;
      import org.springframework.beans.factory.annotation.Autowired;
      import org.springframework.context.annotation.Bean;
      import org.springframework.context.annotation.Configuration;
      import org.springframework.data.redis.connection.RedisConnectionFactory;
      import org.springframework.data.redis.core.HashOperations;
      import org.springframework.data.redis.core.ListOperations;
      import org.springframework.data.redis.core.RedisTemplate;
      import org.springframework.data.redis.core.SetOperations;
      import org.springframework.data.redis.core.ValueOperations;
      import org.springframework.data.redis.core.ZSetOperations;
      import org.springframework.data.redis.serializer.Jackson2JsonRedisSerializer;
      import org.springframework.data.redis.serializer.StringRedisSerializer;
      
      @Configuration
      public class RedisConfig {
          @Autowired
          private RedisConnectionFactory factory;
      
          @Bean
          public RedisTemplate<String, Object> redisTemplate() {
              Jackson2JsonRedisSerializer<Object> jackson2JsonRedisSerializer = new Jackson2JsonRedisSerializer<Object>(Object.class);
              ObjectMapper om = new ObjectMapper();
              om.setVisibility(PropertyAccessor.ALL, JsonAutoDetect.Visibility.ANY);
              om.enableDefaultTyping(ObjectMapper.DefaultTyping.NON_FINAL);
              jackson2JsonRedisSerializer.setObjectMapper(om);
              RedisTemplate<String, Object> template = new RedisTemplate<String, Object>();
              template.setConnectionFactory(factory);
              template.setKeySerializer(new StringRedisSerializer());
              template.setValueSerializer(jackson2JsonRedisSerializer);
              template.setHashKeySerializer(jackson2JsonRedisSerializer);
              template.setHashValueSerializer(jackson2JsonRedisSerializer);
              template.setDefaultSerializer(new StringRedisSerializer());
              template.afterPropertiesSet();
              return template;
          }
      
          @Bean
          public HashOperations<String, String, Object> hashOperations(RedisTemplate<String, Object> redisTemplate) {
              return redisTemplate.opsForHash();
          }
      
          @Bean
          public ValueOperations<String, String> valueOperations(RedisTemplate<String, String> redisTemplate) {
              return redisTemplate.opsForValue();
          }
      
          @Bean
          public ListOperations<String, Object> listOperations(RedisTemplate<String, Object> redisTemplate) {
              return redisTemplate.opsForList();
          }
      
          @Bean
          public SetOperations<String, Object> setOperations(RedisTemplate<String, Object> redisTemplate) {
              return redisTemplate.opsForSet();
          }
      
          @Bean
          public ZSetOperations<String, Object> zSetOperations(RedisTemplate<String, Object> redisTemplate) {
              return redisTemplate.opsForZSet();
          }
      }

      application.properties:

      # REDIS (RedisProperties)
      # Redis數據庫索引(默認為0)
      spring.redis.database=0
      # Redis服務器地址
      spring.redis.host=127.0.0.1
      # Redis服務器連接端口
      spring.redis.port=6379
      # Redis服務器連接密碼(默認為空)
      spring.redis.password=
      # 連接池最大連接數(使用負值表示沒有限制)
      spring.redis.pool.max-active=8
      # 連接池最大阻塞等待時間(使用負值表示沒有限制)
      spring.redis.pool.max-wait=-1
      # 連接池中的最大空閑連接
      spring.redis.pool.max-idle=8
      # 連接池中的最小空閑連接
      spring.redis.pool.min-idle=0
      # 連接超時時間(毫秒)
      spring.redis.timeout=0

       上面的例子還是有問題的

      主要是RedisTemplate序列化問題

      特別是在使用數組操作的時候

      僅供參考學習

      當然也可以使用其他方式解決這些序列化問題 ,就是轉換成字符串,但是不喜歡

      public class RedisCacheUtil {
      
          private static RedisTemplate<String, String> redisTemplate;
      
          public void setRedisTemplate(RedisTemplate<String, String> redisTemp) {
              redisTemplate = redisTemp;
          }
      
          /* ----------- common --------- */
          public static Collection<String> keys(String pattern) {
              return redisTemplate.keys(pattern);
          }
      
          public static void delete(String key) {
              redisTemplate.delete(key);
          }
      
          public static void delete(Collection<String> key) {
              redisTemplate.delete(key);
          }
      
          /* ----------- string --------- */
          public static <T> T get(String key, Class<T> clazz) {
              String value = redisTemplate.opsForValue().get(key);
              return parseJson(value, clazz);
          }
      
          public static <T> List<T> mget(Collection<String> keys, Class<T> clazz) {
              List<String> values = redisTemplate.opsForValue().multiGet(keys);
              return parseJsonList(values, clazz);
          }
      
          public static <T> void set(String key, T obj, Long timeout, TimeUnit unit) {
              if (obj == null) {
                  return;
              }
      
              String value = toJson(obj);
              if (timeout != null) {
                  redisTemplate.opsForValue().set(key, value, timeout, unit);
              } else {
                  redisTemplate.opsForValue().set(key, value);
              }
          }
      
          public static <T> T getAndSet(String key, T obj, Class<T> clazz) {
              if (obj == null) {
                  return get(key, clazz);
              }
      
              String value = redisTemplate.opsForValue().getAndSet(key, toJson(obj));
              return parseJson(value, clazz);
          }
      
          public static int decrement(String key, int delta) {
              Long value = redisTemplate.opsForValue().increment(key, -delta);
              return value.intValue();
          }
      
          public static int increment(String key, int delta) {
              Long value = redisTemplate.opsForValue().increment(key, delta);
              return value.intValue();
          }
      
          /* ----------- list --------- */
          public static int size(String key) {
              return redisTemplate.opsForList().size(key).intValue();
          }
      
          public static <T> List<T> range(String key, long start, long end, Class<T> clazz) {
              List<String> list = redisTemplate.opsForList().range(key, start, end);
              return parseJsonList(list, clazz);
          }
      
          public static void rightPushAll(String key, Collection<?> values, Long timeout,
                                          TimeUnit unit) {
              if (values == null || values.isEmpty()) {
                  return;
              }
      
              redisTemplate.opsForList().rightPushAll(key, toJsonList(values));
              if (timeout != null) {
                  redisTemplate.expire(key, timeout, unit);
              }
          }
      
          public static <T> void leftPush(String key, T obj) {
              if (obj == null) {
                  return;
              }
      
              redisTemplate.opsForList().leftPush(key, toJson(obj));
          }
      
          public static <T> T leftPop(String key, Class<T> clazz) {
              String value = redisTemplate.opsForList().leftPop(key);
              return parseJson(value, clazz);
          }
      
          public static void remove(String key, int count, Object obj) {
              if (obj == null) {
                  return;
              }
      
              redisTemplate.opsForList().remove(key, count, toJson(obj));
          }
      
          /* ----------- zset --------- */
          public static int zcard(String key) {
              return redisTemplate.opsForZSet().zCard(key).intValue();
          }
      
          public static <T> List<T> zrange(String key, long start, long end, Class<T> clazz) {
              Set<String> set = redisTemplate.opsForZSet().range(key, start, end);
              return parseJsonList(setToList(set), clazz);
          }
      
          private static List<String> setToList(Set<String> set) {
              if (set == null) {
                  return null;
              }
              return new ArrayList<String>(set);
          }
      
          public static void zadd(String key, Object obj, double score) {
              if (obj == null) {
                  return;
              }
              redisTemplate.opsForZSet().add(key, toJson(obj), score);
          }
      
          public static void zaddAll(String key, List<TypedTuple<?>> tupleList, Long timeout, TimeUnit unit) {
              if (tupleList == null || tupleList.isEmpty()) {
                  return;
              }
      
              Set<TypedTuple<String>> tupleSet = toTupleSet(tupleList);
              redisTemplate.opsForZSet().add(key, tupleSet);
              if (timeout != null) {
                  redisTemplate.expire(key, timeout, unit);
              }
          }
      
          private static Set<TypedTuple<String>> toTupleSet(List<TypedTuple<?>> tupleList) {
              Set<TypedTuple<String>> tupleSet = new LinkedHashSet<TypedTuple<String>>();
              for (TypedTuple<?> t : tupleList) {
                  tupleSet.add(new DefaultTypedTuple<String>(toJson(t.getValue()), t.getScore()));
              }
              return tupleSet;
          }
      
          public static void zrem(String key, Object obj) {
              if (obj == null) {
                  return;
              }
              redisTemplate.opsForZSet().remove(key, toJson(obj));
          }
      
          public static void unionStore(String destKey, Collection<String> keys, Long timeout, TimeUnit unit) {
              if (keys == null || keys.isEmpty()) {
                  return;
              }
      
              Object[] keyArr = keys.toArray();
              String key = (String) keyArr[0];
      
              Collection<String> otherKeys = new ArrayList<String>(keys.size() - 1);
              for (int i = 1; i < keyArr.length; i++) {
                  otherKeys.add((String) keyArr[i]);
              }
      
              redisTemplate.opsForZSet().unionAndStore(key, otherKeys, destKey);
              if (timeout != null) {
                  redisTemplate.expire(destKey, timeout, unit);
              }
          }
      
          /* ----------- tool methods --------- */
          public static String toJson(Object obj) {
              return JSON.toJSONString(obj, SerializerFeature.SortField);
          }
      
          public static <T> T parseJson(String json, Class<T> clazz) {
              return JSON.parseObject(json, clazz);
          }
      
          public static List<String> toJsonList(Collection<?> values) {
              if (values == null) {
                  return null;
              }
      
              List<String> result = new ArrayList<String>();
              for (Object obj : values) {
                  result.add(toJson(obj));
              }
              return result;
          }
      
          public static <T> List<T> parseJsonList(List<String> list, Class<T> clazz) {
              if (list == null) {
                  return null;
              }
      
              List<T> result = new ArrayList<T>();
              for (String s : list) {
                  result.add(parseJson(s, clazz));
              }
              return result;
          }
      }

      又一版本:

      @Component
      public class RedisCache {
          @Autowired
          private RedisTemplate<String, Object> redisTemplate;
      
          public RedisCache() {
          }
      
          public RedisTemplate<String, Object> getRedisTemplate() {
              return this.redisTemplate;
          }
      
          public void setRedisTemplate(RedisTemplate<String, Object> redisTemplate) {
              this.redisTemplate = redisTemplate;
          }
      
          public Object get(Object key) {
              final String keyf = key.toString();
              Object object = null;
              object = this.redisTemplate.execute(new RedisCallback<Object>() {
                  public Object doInRedis(RedisConnection connection) throws DataAccessException {
                      byte[] key = keyf.getBytes();
                      byte[] value = connection.get(key);
                      return value == null ? null : RedisCache.this.toObject(value);
                  }
              });
              return object;
          }
      
          public void put(Object key, final Object value, final long liveTime) {
              final String keyf = key.toString();
              this.redisTemplate.execute(new RedisCallback<Long>() {
                  public Long doInRedis(RedisConnection connection) throws DataAccessException {
                      byte[] keyb = keyf.getBytes();
                      byte[] valueb = RedisCache.this.toByteArray(value);
                      connection.set(keyb, valueb);
                      if (liveTime > 0L) {
                          connection.expire(keyb, liveTime);
                      }
      
                      return 1L;
                  }
              });
          }
      
          private byte[] toByteArray(Object obj) {
              byte[] bytes = null;
              ByteArrayOutputStream bos = new ByteArrayOutputStream();
      
              try {
                  ObjectOutputStream oos = new ObjectOutputStream(bos);
                  oos.writeObject(obj);
                  oos.flush();
                  bytes = bos.toByteArray();
                  oos.close();
                  bos.close();
              } catch (IOException var5) {
                  var5.printStackTrace();
              }
      
              return bytes;
          }
      
          private Object toObject(byte[] bytes) {
              Object obj = null;
      
              try {
                  ByteArrayInputStream bis = new ByteArrayInputStream(bytes);
                  ObjectInputStream ois = new ObjectInputStream(bis);
                  obj = ois.readObject();
                  ois.close();
                  bis.close();
              } catch (IOException var5) {
                  var5.printStackTrace();
              } catch (ClassNotFoundException var6) {
                  var6.printStackTrace();
              }
      
              return obj;
          }
      
          public void del(Object key) {
              final String keyf = key.toString();
              this.redisTemplate.execute(new RedisCallback<Long>() {
                  public Long doInRedis(RedisConnection connection) throws DataAccessException {
                      return connection.del(new byte[][]{keyf.getBytes()});
                  }
              });
          }
      
          public void exprie(Object key, final long liveTime) {
              final String keyf = key.toString();
              this.redisTemplate.execute(new RedisCallback<Boolean>() {
                  public Boolean doInRedis(RedisConnection connection) throws DataAccessException {
                      return connection.expire(keyf.getBytes(), liveTime);
                  }
              });
          }
      
          public Boolean exist(Object key) {
              final String keyf = key.toString();
              return (Boolean)this.redisTemplate.execute(new RedisCallback<Boolean>() {
                  public Boolean doInRedis(RedisConnection connection) throws DataAccessException {
                      return connection.exists(keyf.getBytes());
                  }
              });
          }
      
          public void clear() {
              this.redisTemplate.execute(new RedisCallback<String>() {
                  public String doInRedis(RedisConnection connection) throws DataAccessException {
                      connection.flushDb();
                      return "ok";
                  }
              });
          }
      
          public Long incr(Object key) {
              final String keyf = key.toString();
              return (Long)this.redisTemplate.execute(new RedisCallback<Long>() {
                  public Long doInRedis(RedisConnection connection) throws DataAccessException {
                      return connection.incr(keyf.getBytes());
                  }
              });
          }
      
          public Long decr(Object key) {
              final String keyf = key.toString();
              return (Long)this.redisTemplate.execute(new RedisCallback<Long>() {
                  public Long doInRedis(RedisConnection connection) throws DataAccessException {
                      return connection.decr(keyf.getBytes());
                  }
              });
          }
      
          public Set<String> keys(String key) {
              Set<String> keys = this.redisTemplate.keys(key);
              return keys;
          }
      }

       

      原文鏈接 http://www.rzrgm.cn/hongdada/p/9141125.html

      posted @ 2018-07-28 10:22  樓蘭胡楊  閱讀(8340)  評論(0)    收藏  舉報
      主站蜘蛛池模板: 国产在线观看免费观看| 26uuu另类亚洲欧美日本| 韩国深夜福利视频在线观看 | 国产一区国产精品自拍| 久久99精品国产麻豆婷婷| 亚洲一区二区日韩综合久久| 色欲av亚洲一区无码少妇| 九九热在线视频只有精品| 国产精品人妻中文字幕| 国产无套内射又大又猛又粗又爽| 亚洲暴爽av人人爽日日碰| 婷婷丁香五月六月综合激情啪| 乱女伦露脸对白在线播放 | 99久久婷婷国产综合精品青草漫画| 中文字幕无码专区一VA亚洲V专| 中文字幕精品亚洲无线码二区| 托里县| 99国产精品白浆无码流出| 六十路老熟妇乱子伦视频| 亚洲精品无码久久久影院相关影片| 国产av熟女一区二区三区| 亚洲性线免费观看视频成熟| 四虎永久精品在线视频| 中国女人熟毛茸茸A毛片| 国产SM重味一区二区三区| 美女把尿囗扒开让男人添| 国产精品小视频一区二页| 成人av一区二区三区| 99riav精品免费视频观看| 亚洲熟女国产熟女二区三区| 婷婷六月天在线| 国产精品乱一区二区三区| 亚洲成人资源在线观看| 97国产揄拍国产精品人妻| 老女老肥熟国产在线视频| 亚洲精品第一页中文字幕| 免费午夜无码片在线观看影院| 亚洲国产精品无码久久久| 污污网站18禁在线永久免费观看| 美乳丰满人妻无码视频| 人妻中文字幕精品系列|