content: package com.gm.wj.redis;
  
  import org.springframework.beans.factory.annotation.Autowired;
  import org.springframework.data.redis.core.*;
  import org.springframework.stereotype.Service;
  
  import java.util.Set;
  import java.util.concurrent.TimeUnit;
  
  /**
   * Redis service.
   *
   * @author Evan
   * @date 2020/3/11 12:42
   */
  @Service
  public class RedisService {
      @Autowired
      private RedisTemplate<String, Object> redisTemplate;
  
      public void set(String key, Object value, long time) {
          redisTemplate.opsForValue().set(key, value, time, TimeUnit.SECONDS);
      }
  
      public void set(String key, Object value) {
          redisTemplate.opsForValue().set(key, value);
      }
  
      public Object get(String key) {
          return redisTemplate.opsForValue().get(key);
      }
  
      public Boolean delete(String key) {
          return redisTemplate.delete(key);
      }
  
      public Long delete(Set<String> keys) {
          return redisTemplate.delete(keys);
      }
  
      public Set<String> getKeysByPattern(String pattern) {
          return redisTemplate.keys(pattern);
      }
  }
  