redis.properties

#redis连接池配置参数
redis.pool.maxTotal=200
redis.pool.maxIdle=50
redis.pool.minIdle=10
redis.pool.testOnBorrow=true
redis.pool.testOnReturn=true
redis.pool.fairness=false
redis.pool.maxWaitMillis=20000
redis.pool.blockWhenExhausted=true

#格式:redis://:[密码]@[服务器地址]:[端口]/[db index]
redis.uri = redis://:[email protected]:6379/0

redis.host = 172.28.1.239
redis.port = 20000
redis.timeout=30000
redis.password = 12345
redis.database = 0

spring-jedis.xml



     
    
    

        
    
        
        
        
        
        
        
        
        
    

    
    
        
        
            
                
                    
                
            
        
    

    
    
        
        
        
        
        
        
    

测试

    public static void main(String[] args) {
        ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("classpath:redis/spring-jedis.xml");
        JedisPool jedisPool = (JedisPool) context.getBean("jedisPool");
        Jedis jedis = jedisPool.getResource();
        String setVal = jedis.set("key123", "value123");
        System.out.println(setVal);
        jedis.del("key123");
        // 事物操作
        Transaction multi = jedis.multi();
        multi.set("key2","val2");
        Map hashMap = new HashMap<>();
        hashMap.put("name","ttest");
        hashMap.put("age","123");
        multi.hmset("hash1", hashMap);
        multi.exec();
    }