Redis使用实例(RedisHelper)

本文详细介绍了RedisHelper的使用,包括连接配置、基本操作如字符串、哈希、列表、集合和有序集合的存取方法,以及事务处理和过期策略等,旨在帮助开发者高效地在项目中应用Redis。
摘要由CSDN通过智能技术生成
public class RedisHelper {
   
    private static JedisPool pool = null;
    static {
        if (pool == null) {
        JedisPoolConfig config = new JedisPoolConfig();
        // 控制一个pool可分配多少个jedis实例,通过pool.getResource()来获取;
            // 如果赋值为-1,则表示不限制;如果pool已经分配了maxActive个jedis实例,则此时pool的状态为exhausted(耗尽)。
            config.setMaxTotal(500);
            // 控制一个pool最多有多少个状态为idle(空闲的)的jedis实例。
            config.setMaxIdle(10);
            // 在borrow一个jedis实例时,是否提前进行validate操作;如果为true,则得到的jedis实例均是可用的;
            config.setTestOnBorrow(true);
            config.setTestOnReturn(true);
// 获取连接池 100000毫秒延时
            // pool = new JedisPool(config, "10.98.103.6", 6379, 100000);
            if (FrontedConst.Redis_IP != null
                    && FrontedConst.Redis_Port != null) {
                String Redis_IP = FrontedConst.Redis_IP;
                int Redis_Port = Integer.parseInt(FrontedConst.Redis_Port);
                pool = new JedisPool(config, Redis_IP, Redis_Port, 100000);
            } else {FEPViewUtils.getAwtUtil().writeLogger(
                        "Please check configuration file.");
            }
 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值