Warning: Undefined array key "night" in /www/wwwroot/dhaomu.com/wp-content/themes/b2/header.php on line 18

Java技术redis轻量工具类代码

Java技术:redis轻量工具类。Java技术redis轻量工具类代码

代码演示

<dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-data-redis</artifactId>
</dependency>

spring:
  redis:
    host: 127.0.0.1
    port: 6379
    jedis:
      pool:
        max-active: 8
        max-wait: -1
        max-idle: 500
        min-idle: 0


import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Component;

import java.util.List;

@Component
public class RedisUtil {

    @Autowired
    private RedisTemplate<Object, Object> redisTemplate;

    public <E> void put(String key, E value) {
        redisTemplate.opsForValue().set(key, value);
    }

    public Boolean del(String key) {
        return redisTemplate.delete(key);
    }

    public <E> E getSingle(String key, Class<E> cls) {
        Object res = redisTemplate.opsForValue().get(key);
        return cast(res, cls);
    }

    public <E> List<E> getList(String key, Class<E> cls) {
        Object res = redisTemplate.opsForValue().get(key);
        return castList(res, cls);
    }


    @SuppressWarnings("unchecked")
    private static <T> T cast(Object obj, Class<T> cls) {
        return (T) obj;
    }


    @SuppressWarnings("unchecked")
    private static <T> List<T> castList(Object obj, Class<T> cls) {
        return (List<T>) obj;
    }
}
温馨提示:
1.本站大部分内容均收集于网络!若内容若侵犯到您的权益,请发送邮件至:duhaomu@163.com,我们将第一时间处理!
2.资源所需价格并非资源售卖价格,是收集、整理、编辑详情以及本站运营的适当补贴,并且本站不提供任何免费技术支持。
3.所有资源仅限于参考和学习,版权归原作者所有,更多请阅读网站声明

给TA赞赏
共{{data.count}}人
人已赞赏
编程技巧

织梦教程DedeCMS获得某篇文章内容的几种方法

2016-5-14 9:00:00

编程技巧

PHP子类继承父类学习笔记!PHP子类继承父类实例代码

2016-5-29 9:00:00

0 条回复 A文章作者 M管理员

Warning: Trying to access array offset on value of type null in /www/wwwroot/dhaomu.com/wp-content/themes/b2/functions.php on line 3914

Warning: Trying to access array offset on value of type null in /www/wwwroot/dhaomu.com/wp-content/themes/b2/functions.php on line 3914
----《》
    暂无讨论,说说你的看法吧
个人中心
购物车
优惠劵
今日签到
有新私信 私信列表
搜索