e2

滴滴侠,fai抖

  博客园 :: 首页 :: 博问 :: 闪存 :: 新随笔 :: 联系 :: 订阅 订阅 :: 管理 ::

SpringBoot集成Redis

 1.添加redis依赖

  1.  
    <dependency>
  2.  
    <groupId>org.springframework.boot</groupId>
  3.  
    <artifactId>spring-boot-starter-data-redis</artifactId>
  4.  
    </dependency>
  5.  
    <dependency>
  6.  
    <groupId>org.apache.commons</groupId>
  7.  
    <artifactId>commons-pool2</artifactId>
  8.  
    </dependency>

2.在application.properties中添加redis配置信息

  1.  
    spring.redis.host=127.0.0.1
  2.  
    # Redis服务器连接端口
  3.  
    spring.redis.port=6379
  4.  
    # Redis服务器连接密码(默认为空)
  5.  
    spring.redis.password=
  6.  
    # 连接池最大连接数(使用负值表示没有限制)
  7.  
    spring.redis.lettuce.pool.max-active=8
  8.  
    # 连接池最大阻塞等待时间(使用负值表示没有限制)
  9.  
    spring.redis.lettuce.pool.max-wait=-1
  10.  
    # 连接池中的最大空闲连接
  11.  
    spring.redis.lettuce.pool.max-idle=8
  12.  
    # 连接池中的最小空闲连接
  13.  
    spring.redis.lettuce.pool.min-idle=0
  14.  
    # 连接超时时间(毫秒)
  15.  
    spring.redis.timeout=30000

3.SpringBoot启动类中添加注解配置

  1.  
    @EnableCaching
  2.  
    @EnableRedisRepositories
  3.  
    //注解开启使用RedisRepositories
  4.  
    //CRUD操作将会操作redis中的数据
  5.  
    @SpringBootApplication
  6.  
    public class RedisApplication {
  7.  
     
  8.  
    public static void main(String[] args) {
  9.  
    SpringApplication.run(RedisApplication.class, args);
  10.  
    }
  11.  
     
  12.  
    }

 

4.创建实体类Entity

  1.  
    @Data
  2.  
    @RedisHash("user")
  3.  
    //RedisHash非常重要
  4.  
    //user表示在redis中新建user集合
  5.  
    //之后所有的UserEntity的保存操作全部会保存在user这个集合中
  6.  
    //保存时Key的格式为——user:id
  7.  
    public class UserEntity{
  8.  
    @Id
  9.  
    private Long id;
  10.  
     
  11.  
    private String name;
  12.  
     
  13.  
    private Integer age;
  14.  
     
  15.  
    private Date createTime = new Date();
  16.  
    }

5.创建Dao层——数据操作层

  1.  
    @Repository
  2.  
    public interface UserDao extends CrudRepository<UserEntity,Long> {
  3.  
    }

6.创建Service层——服务层

  1.  
    @Service
  2.  
    public class UserService {
  3.  
     
  4.  
    @Autowired
  5.  
    private UserDao userDao;
  6.  
     
  7.  
    //因为使用了RedisRepositories,所以简单的crud将不用使用RedisTemplate
  8.  
    // @Autowired
  9.  
    // private RedisTemplate redisTemplate;
  10.  
     
  11.  
     
  12.  
    /**
  13.  
    * 按user:id的方式存入redis
  14.  
    * @param user
  15.  
    */
  16.  
    public void save(UserEntity user){
  17.  
    //redisTemplate.opsForValue().set(new Random().nextDouble() + "",user);
  18.  
     
  19.  
    userDao.save(user);
  20.  
     
  21.  
    }
  22.  
     
  23.  
    /**
  24.  
    * 根据key从redis中查找对应value
  25.  
    * @param id
  26.  
    * @return
  27.  
    */
  28.  
    public UserEntity findOne(Long id){
  29.  
     
  30.  
    //UserEntity user = (UserEntity) redisTemplate.opsForValue().get(key);
  31.  
     
  32.  
    UserEntity user = userDao.findById(id).get();
  33.  
     
  34.  
    return user;
  35.  
    }
  36.  
    }

7.创建Controller层——控制层

  1.  
    @RestController
  2.  
    @RequestMapping("user")
  3.  
    public class UserController {
  4.  
     
  5.  
    @Autowired
  6.  
    private UserService userService;
  7.  
     
  8.  
    /**
  9.  
    * 保存到redis中
  10.  
    * @return
  11.  
    */
  12.  
    @GetMapping("save")
  13.  
    public String save(){
  14.  
     
  15.  
    UserEntity user = new UserEntity();
  16.  
     
  17.  
    user.setName(String.valueOf(new Random().nextInt(100000)));
  18.  
     
  19.  
    user.setAge(new Random().nextInt(100000));
  20.  
     
  21.  
    userService.save(user);
  22.  
     
  23.  
    System.out.println(user.toString());
  24.  
     
  25.  
    return "success";
  26.  
    }
  27.  
     
  28.  
    /**
  29.  
    * 根据key从redis中查找value
  30.  
    * @param id
  31.  
    * @return
  32.  
    */
  33.  
    @GetMapping("find/{id}")
  34.  
    public String find(@PathVariable Long id){
  35.  
    UserEntity user = userService.findOne(id);
  36.  
     
  37.  
    System.out.println(user);
  38.  
    return "success";
  39.  
    }
  40.  
    }

8.redis配置类

  1.  
    @Configuration
  2.  
    public class RedisConfig {
  3.  
     
  4.  
    @Bean
  5.  
    public RedisTemplate<String, Object> redisTemplate(RedisConnectionFactory factory) {
  6.  
    RedisTemplate<String, Object> template = new RedisTemplate<String, Object>();
  7.  
    template.setConnectionFactory(factory);
  8.  
    Jackson2JsonRedisSerializer jackson2JsonRedisSerializer = new Jackson2JsonRedisSerializer(Object.class);
  9.  
    ObjectMapper om = new ObjectMapper();
  10.  
    om.setVisibility(PropertyAccessor.ALL, JsonAutoDetect.Visibility.ANY);
  11.  
    om.enableDefaultTyping(ObjectMapper.DefaultTyping.NON_FINAL);
  12.  
    jackson2JsonRedisSerializer.setObjectMapper(om);
  13.  
    StringRedisSerializer stringRedisSerializer = new StringRedisSerializer();
  14.  
    // key采用String的序列化方式
  15.  
    template.setKeySerializer(stringRedisSerializer);
  16.  
    // hash的key也采用String的序列化方式
  17.  
    template.setHashKeySerializer(stringRedisSerializer);
  18.  
    // value序列化方式采用jackson
  19.  
    template.setValueSerializer(jackson2JsonRedisSerializer);
  20.  
    // hash的value序列化方式采用jackson
  21.  
    template.setHashValueSerializer(jackson2JsonRedisSerializer);
  22.  
    template.afterPropertiesSet();
  23.  
    return template;
  24.  
    }
  25.  
    }

Redis中的结构为

redis封装工具类:

  1.  
    @Component
  2.  
    public class RedisUtils {
  3.  
     
  4.  
    @Autowired
  5.  
    private RedisTemplate<String, Object> redisTemplate;
  6.  
     
  7.  
    // =============================common============================
  8.  
     
  9.  
    /**
  10.  
    * 指定缓存失效时间
  11.  
    *
  12.  
    * @param key 键
  13.  
    * @param time 时间(秒)
  14.  
    * @return
  15.  
    */
  16.  
    public boolean expire(String key, long time) {
  17.  
    try {
  18.  
    if (time > 0) {
  19.  
    redisTemplate.expire(key, time, TimeUnit.SECONDS);
  20.  
    }
  21.  
    return true;
  22.  
    } catch (Exception e) {
  23.  
    e.printStackTrace();
  24.  
    return false;
  25.  
    }
  26.  
    }
  27.  
     
  28.  
    /**
  29.  
    * 根据key 获取过期时间
  30.  
    *
  31.  
    * @param key 键 不能为null
  32.  
    * @return 时间(秒) 返回0代表为永久有效
  33.  
    */
  34.  
    public long getExpire(String key) {
  35.  
    return redisTemplate.getExpire(key, TimeUnit.SECONDS);
  36.  
    }
  37.  
     
  38.  
    /**
  39.  
    * 判断key是否存在
  40.  
    *
  41.  
    * @param key 键
  42.  
    * @return true 存在 false不存在
  43.  
    */
  44.  
    public boolean hasKey(String key) {
  45.  
    try {
  46.  
    return redisTemplate.hasKey(key);
  47.  
    } catch (Exception e) {
  48.  
    e.printStackTrace();
  49.  
    return false;
  50.  
    }
  51.  
    }
  52.  
     
  53.  
    /**
  54.  
    * 删除缓存
  55.  
    *
  56.  
    * @param key 可以传一个值 或多个
  57.  
    */
  58.  
    @SuppressWarnings("unchecked")
  59.  
    public void del(String... key) {
  60.  
    if (key != null && key.length > 0) {
  61.  
    if (key.length == 1) {
  62.  
    redisTemplate.delete(key[0]);
  63.  
    } else {
  64.  
    redisTemplate.delete(CollectionUtils.arrayToList(key));
  65.  
    }
  66.  
    }
  67.  
    }
  68.  
    // ============================String=============================
  69.  
     
  70.  
    /**
  71.  
    * 普通缓存获取
  72.  
    *
  73.  
    * @param key 键
  74.  
    * @return
  75.  
    */
  76.  
    public Object get(String key) {
  77.  
    return key == null ? null : redisTemplate.opsForValue().get(key);
  78.  
    }
  79.  
     
  80.  
    /**
  81.  
    * 普通缓存放入
  82.  
    *
  83.  
    * @param key 键
  84.  
    * @param value 值
  85.  
    * @return true成功 false失败
  86.  
    */
  87.  
    public boolean set(String key, Object value) {
  88.  
    try {
  89.  
    redisTemplate.opsForValue().set(key, value);
  90.  
    return true;
  91.  
    } catch (Exception e) {
  92.  
    e.printStackTrace();
  93.  
    return false;
  94.  
    }
  95.  
    }
  96.  
     
  97.  
    /**
  98.  
    * 普通缓存放入并设置时间
  99.  
    *
  100.  
    * @param key 键
  101.  
    * @param value 值
  102.  
    * @param time 时间(秒) time要大于0 如果time小于等于0 将设置无限期
  103.  
    * @return true成功 false 失败
  104.  
    */
  105.  
    public boolean set(String key, Object value, long time) {
  106.  
    try {
  107.  
    if (time > 0) {
  108.  
    redisTemplate.opsForValue().set(key, value, time, TimeUnit.SECONDS);
  109.  
    } else {
  110.  
    set(key, value);
  111.  
    }
  112.  
    return true;
  113.  
    } catch (Exception e) {
  114.  
    e.printStackTrace();
  115.  
    return false;
  116.  
    }
  117.  
    }
  118.  
     
  119.  
    /**
  120.  
    * 递增
  121.  
    *
  122.  
    * @param key 键
  123.  
    * @param delta 要增加几(大于0)
  124.  
    * @return
  125.  
    */
  126.  
    public long incr(String key, long delta) {
  127.  
    if (delta < 0) {
  128.  
    throw new RuntimeException("递增因子必须大于0");
  129.  
    }
  130.  
    return redisTemplate.opsForValue().increment(key, delta);
  131.  
    }
  132.  
     
  133.  
    /**
  134.  
    * 递减
  135.  
    *
  136.  
    * @param key 键
  137.  
    * @param delta 要减少几(小于0)
  138.  
    * @return
  139.  
    */
  140.  
    public long decr(String key, long delta) {
  141.  
    if (delta < 0) {
  142.  
    throw new RuntimeException("递减因子必须大于0");
  143.  
    }
  144.  
    return redisTemplate.opsForValue().increment(key, -delta);
  145.  
    }
  146.  
    // ================================Map=================================
  147.  
     
  148.  
    /**
  149.  
    * HashGet
  150.  
    *
  151.  
    * @param key 键 不能为null
  152.  
    * @param item 项 不能为null
  153.  
    * @return
  154.  
    */
  155.  
    public Object hget(String key, String item) {
  156.  
    return redisTemplate.opsForHash().get(key, item);
  157.  
    }
  158.  
     
  159.  
    /**
  160.  
    * 获取hashKey对应的所有键值
  161.  
    *
  162.  
    * @param key 键
  163.  
    * @return 对应的多个键值
  164.  
    */
  165.  
    public Map<Object, Object> hmget(String key) {
  166.  
    return redisTemplate.opsForHash().entries(key);
  167.  
    }
  168.  
     
  169.  
    /**
  170.  
    * HashSet
  171.  
    *
  172.  
    * @param key 键
  173.  
    * @param map 对应多个键值
  174.  
    * @return true 成功 false 失败
  175.  
    */
  176.  
    public boolean hmset(String key, Map<String, Object> map) {
  177.  
    try {
  178.  
    redisTemplate.opsForHash().putAll(key, map);
  179.  
    return true;
  180.  
    } catch (Exception e) {
  181.  
    e.printStackTrace();
  182.  
    return false;
  183.  
    }
  184.  
    }
  185.  
     
  186.  
    /**
  187.  
    * HashSet 并设置时间
  188.  
    *
  189.  
    * @param key 键
  190.  
    * @param map 对应多个键值
  191.  
    * @param time 时间(秒)
  192.  
    * @return true成功 false失败
  193.  
    */
  194.  
    public boolean hmset(String key, Map<String, Object> map, long time) {
  195.  
    try {
  196.  
    redisTemplate.opsForHash().putAll(key, map);
  197.  
    if (time > 0) {
  198.  
    expire(key, time);
  199.  
    }
  200.  
    return true;
  201.  
    } catch (Exception e) {
  202.  
    e.printStackTrace();
  203.  
    return false;
  204.  
    }
  205.  
    }
  206.  
     
  207.  
    /**
  208.  
    * 向一张hash表中放入数据,如果不存在将创建
  209.  
    *
  210.  
    * @param key 键
  211.  
    * @param item 项
  212.  
    * @param value 值
  213.  
    * @return true 成功 false失败
  214.  
    */
  215.  
    public boolean hset(String key, String item, Object value) {
  216.  
    try {
  217.  
    redisTemplate.opsForHash().put(key, item, value);
  218.  
    return true;
  219.  
    } catch (Exception e) {
  220.  
    e.printStackTrace();
  221.  
    return false;
  222.  
    }
  223.  
    }
  224.  
     
  225.  
    /**
  226.  
    * 向一张hash表中放入数据,如果不存在将创建
  227.  
    *
  228.  
    * @param key 键
  229.  
    * @param item 项
  230.  
    * @param value 值
  231.  
    * @param time 时间(秒) 注意:如果已存在的hash表有时间,这里将会替换原有的时间
  232.  
    * @return true 成功 false失败
  233.  
    */
  234.  
    public boolean hset(String key, String item, Object value, long time) {
  235.  
    try {
  236.  
    redisTemplate.opsForHash().put(key, item, value);
  237.  
    if (time > 0) {
  238.  
    expire(key, time);
  239.  
    }
  240.  
    return true;
  241.  
    } catch (Exception e) {
  242.  
    e.printStackTrace();
  243.  
    return false;
  244.  
    }
  245.  
    }
  246.  
     
  247.  
    /**
  248.  
    * 删除hash表中的值
  249.  
    *
  250.  
    * @param key 键 不能为null
  251.  
    * @param item 项 可以使多个 不能为null
  252.  
    */
  253.  
    public void hdel(String key, Object... item) {
  254.  
    redisTemplate.opsForHash().delete(key, item);
  255.  
    }
  256.  
     
  257.  
    /**
  258.  
    * 判断hash表中是否有该项的值
  259.  
    *
  260.  
    * @param key 键 不能为null
  261.  
    * @param item 项 不能为null
  262.  
    * @return true 存在 false不存在
  263.  
    */
  264.  
    public boolean hHasKey(String key, String item) {
  265.  
    return redisTemplate.opsForHash().hasKey(key, item);
  266.  
    }
  267.  
     
  268.  
    /**
  269.  
    * hash递增 如果不存在,就会创建一个 并把新增后的值返回
  270.  
    *
  271.  
    * @param key 键
  272.  
    * @param item 项
  273.  
    * @param by 要增加几(大于0)
  274.  
    * @return
  275.  
    */
  276.  
    public double hincr(String key, String item, double by) {
  277.  
    return redisTemplate.opsForHash().increment(key, item, by);
  278.  
    }
  279.  
     
  280.  
    /**
  281.  
    * hash递减
  282.  
    *
  283.  
    * @param key 键
  284.  
    * @param item 项
  285.  
    * @param by 要减少记(小于0)
  286.  
    * @return
  287.  
    */
  288.  
    public double hdecr(String key, String item, double by) {
  289.  
    return redisTemplate.opsForHash().increment(key, item, -by);
  290.  
    }
  291.  
    // ============================set=============================
  292.  
     
  293.  
    /**
  294.  
    * 根据key获取Set中的所有值
  295.  
    *
  296.  
    * @param key 键
  297.  
    * @return
  298.  
    */
  299.  
    public Set<Object> sGet(String key) {
  300.  
    try {
  301.  
    return redisTemplate.opsForSet().members(key);
  302.  
    } catch (Exception e) {
  303.  
    e.printStackTrace();
  304.  
    return null;
  305.  
    }
  306.  
    }
  307.  
     
  308.  
    /**
  309.  
    * 根据value从一个set中查询,是否存在
  310.  
    *
  311.  
    * @param key 键
  312.  
    * @param value 值
  313.  
    * @return true 存在 false不存在
  314.  
    */
  315.  
    public boolean sHasKey(String key, Object value) {
  316.  
    try {
  317.  
    return redisTemplate.opsForSet().isMember(key, value);
  318.  
    } catch (Exception e) {
  319.  
    e.printStackTrace();
  320.  
    return false;
  321.  
    }
  322.  
    }
  323.  
     
  324.  
    /**
  325.  
    * 将数据放入set缓存
  326.  
    *
  327.  
    * @param key 键
  328.  
    * @param values 值 可以是多个
  329.  
    * @return 成功个数
  330.  
    */
  331.  
    public long sSet(String key, Object... values) {
  332.  
    try {
  333.  
    return redisTemplate.opsForSet().add(key, values);
  334.  
    } catch (Exception e) {
  335.  
    e.printStackTrace();
  336.  
    return 0;
  337.  
    }
  338.  
    }
  339.  
     
  340.  
    /**
  341.  
    * 将set数据放入缓存
  342.  
    *
  343.  
    * @param key 键
  344.  
    * @param time 时间(秒)
  345.  
    * @param values 值 可以是多个
  346.  
    * @return 成功个数
  347.  
    */
  348.  
    public long sSetAndTime(String key, long time, Object... values) {
  349.  
    try {
  350.  
    Long count = redisTemplate.opsForSet().add(key, values);
  351.  
    if (time > 0)
  352.  
    expire(key, time);
  353.  
    return count;
  354.  
    } catch (Exception e) {
  355.  
    e.printStackTrace();
  356.  
    return 0;
  357.  
    }
  358.  
    }
  359.  
     
  360.  
    /**
  361.  
    * 获取set缓存的长度
  362.  
    *
  363.  
    * @param key 键
  364.  
    * @return
  365.  
    */
  366.  
    public long sGetSetSize(String key) {
  367.  
    try {
  368.  
    return redisTemplate.opsForSet().size(key);
  369.  
    } catch (Exception e) {
  370.  
    e.printStackTrace();
  371.  
    return 0;
  372.  
    }
  373.  
    }
  374.  
     
  375.  
    /**
  376.  
    * 移除值为value的
  377.  
    *
  378.  
    * @param key 键
  379.  
    * @param values 值 可以是多个
  380.  
    * @return 移除的个数
  381.  
    */
  382.  
    public long setRemove(String key, Object... values) {
  383.  
    try {
  384.  
    Long count = redisTemplate.opsForSet().remove(key, values);
  385.  
    return count;
  386.  
    } catch (Exception e) {
  387.  
    e.printStackTrace();
  388.  
    return 0;
  389.  
    }
  390.  
    }
  391.  
    // ===============================list=================================
  392.  
     
  393.  
    /**
  394.  
    * 获取list缓存的内容
  395.  
    *
  396.  
    * @param key 键
  397.  
    * @param start 开始
  398.  
    * @param end 结束 0 到 -1代表所有值
  399.  
    * @return
  400.  
    */
  401.  
    public List<Object> lGet(String key, long start, long end) {
  402.  
    try {
  403.  
    return redisTemplate.opsForList().range(key, start, end);
  404.  
    } catch (Exception e) {
  405.  
    e.printStackTrace();
  406.  
    return null;
  407.  
    }
  408.  
    }
  409.  
     
  410.  
    /**
  411.  
    * 获取list缓存的长度
  412.  
    *
  413.  
    * @param key 键
  414.  
    * @return
  415.  
    */
  416.  
    public long lGetListSize(String key) {
  417.  
    try {
  418.  
    return redisTemplate.opsForList().size(key);
  419.  
    } catch (Exception e) {
  420.  
    e.printStackTrace();
  421.  
    return 0;
  422.  
    }
  423.  
    }
  424.  
     
  425.  
    /**
  426.  
    * 通过索引 获取list中的值
  427.  
    *
  428.  
    * @param key 键
  429.  
    * @param index 索引 index>=0时, 0 表头,1 第二个元素,依次类推;index<0时,-1,表尾,-2倒数第二个元素,依次类推
  430.  
    * @return
  431.  
    */
  432.  
    public Object lGetIndex(String key, long index) {
  433.  
    try {
  434.  
    return redisTemplate.opsForList().index(key, index);
  435.  
    } catch (Exception e) {
  436.  
    e.printStackTrace();
  437.  
    return null;
  438.  
    }
  439.  
    }
  440.  
     
  441.  
    /**
  442.  
    * 将list放入缓存
  443.  
    *
  444.  
    * @param key 键
  445.  
    * @param value 值
  446.  
    * @return
  447.  
    */
  448.  
    public boolean lSet(String key, Object value) {
  449.  
    try {
  450.  
    redisTemplate.opsForList().rightPush(key, value);
  451.  
    return true;
  452.  
    } catch (Exception e) {
  453.  
    e.printStackTrace();
  454.  
    return false;
  455.  
    }
  456.  
    }
  457.  
     
  458.  
    /**
  459.  
    * 将list放入缓存
  460.  
    *
  461.  
    * @param key 键
  462.  
    * @param value 值
  463.  
    * @param time 时间(秒)
  464.  
    * @return
  465.  
    */
  466.  
    public boolean lSet(String key, Object value, long time) {
  467.  
    try {
  468.  
    redisTemplate.opsForList().rightPush(key, value);
  469.  
    if (time > 0)
  470.  
    expire(key, time);
  471.  
    return true;
  472.  
    } catch (Exception e) {
  473.  
    e.printStackTrace();
  474.  
    return false;
  475.  
    }
  476.  
    }
  477.  
     
  478.  
    /**
  479.  
    * 将list放入缓存
  480.  
    *
  481.  
    * @param key 键
  482.  
    * @param value 值
  483.  
    * @return
  484.  
    */
  485.  
    public boolean lSet(String key, List<Object> value) {
  486.  
    try {
  487.  
    redisTemplate.opsForList().rightPushAll(key, value);
  488.  
    return true;
  489.  
    } catch (Exception e) {
  490.  
    e.printStackTrace();
  491.  
    return false;
  492.  
    }
  493.  
    }
  494.  
     
  495.  
    /**
  496.  
    * 将list放入缓存
  497.  
    *
  498.  
    * @param key 键
  499.  
    * @param value 值
  500.  
    * @param time 时间(秒)
  501.  
    * @return
  502.  
    */
  503.  
    public boolean lSet(String key, List<Object> value, long time) {
  504.  
    try {
  505.  
    redisTemplate.opsForList().rightPushAll(key, value);
  506.  
    if (time > 0)
  507.  
    expire(key, time);
  508.  
    return true;
  509.  
    } catch (Exception e) {
  510.  
    e.printStackTrace();
  511.  
    return false;
  512.  
    }
  513.  
    }
  514.  
     
  515.  
    /**
  516.  
    * 根据索引修改list中的某条数据
  517.  
    *
  518.  
    * @param key 键
  519.  
    * @param index 索引
  520.  
    * @param value 值
  521.  
    * @return
  522.  
    */
  523.  
    public boolean lUpdateIndex(String key, long index, Object value) {
  524.  
    try {
  525.  
    redisTemplate.opsForList().set(key, index, value);
  526.  
    return true;
  527.  
    } catch (Exception e) {
  528.  
    e.printStackTrace();
  529.  
    return false;
  530.  
    }
  531.  
    }
  532.  
     
  533.  
    /**
  534.  
    * 移除N个值为value
  535.  
    *
  536.  
    * @param key 键
  537.  
    * @param count 移除多少个
  538.  
    * @param value 值
  539.  
    * @return 移除的个数
  540.  
    */
  541.  
    public long lRemove(String key, long count, Object value) {
  542.  
    try {
  543.  
    Long remove = redisTemplate.opsForList().remove(key, count, value);
  544.  
    return remove;
  545.  
    } catch (Exception e) {
  546.  
    e.printStackTrace();
  547.  
    return 0;
  548.  
    }
  549.  
    }
  550.  
    }

 

posted on 2022-05-03 18:38  纯黑Se丶  阅读(256)  评论(0编辑  收藏  举报