Spring-data-redis (2.0.5) 单机版


Pom文件



    4.0.0

    vip.fkandy
    spring-data-redis
    1.0-SNAPSHOT
    
        1.8
        1.8
        1.8
    

    
        
            org.springframework
            spring-context
        
        
            org.springframework.data
            spring-data-redis
        
        
            vip.fkandy
            spring-data-redis
        
        
            redis.clients
            jedis
        
        
            ch.qos.logback
            logback-core
        
    
    
        
            
                io.spring.platform
                platform-bom
                Cairo-RC1
                pom
                import
            
        
    
    
        
            spring-milestones
            Spring Milestones
            https://repo.spring.io/libs-milestone
            
                false
            
        
    
import org.apache.commons.pool2.impl.GenericObjectPoolConfig;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.connection.RedisPassword;
import org.springframework.data.redis.connection.RedisStandaloneConfiguration;
import org.springframework.data.redis.connection.jedis.JedisClientConfiguration;
import org.springframework.data.redis.connection.jedis.JedisConnectionFactory;
import org.springframework.data.redis.core.RedisTemplate;
import redis.clients.jedis.JedisPoolConfig;

/**
 *  配置相关
 */
@Configuration
public class RedisConfiguration2 {

    @Bean
    public JedisClientConfiguration getJedisClientConfiguration() {
        JedisClientConfiguration.JedisPoolingClientConfigurationBuilder JedisPoolingClientConfigurationBuilder = (
                JedisClientConfiguration.JedisPoolingClientConfigurationBuilder) JedisClientConfiguration.builder();
        GenericObjectPoolConfig GenericObjectPoolConfig = new GenericObjectPoolConfig();
        GenericObjectPoolConfig.setMaxIdle(1000);
        GenericObjectPoolConfig.setMaxTotal(100);
        GenericObjectPoolConfig.setMinIdle(100);
        return JedisPoolingClientConfigurationBuilder.poolConfig(GenericObjectPoolConfig).build();
    }

    @Bean
    public JedisConnectionFactory getJedisConnectionFactory() {
        RedisStandaloneConfiguration redisStandaloneConfiguration = new RedisStandaloneConfiguration();
        redisStandaloneConfiguration.setDatabase(0);
        redisStandaloneConfiguration.setHostName("localhost");
        redisStandaloneConfiguration.setPassword(RedisPassword.none());
        redisStandaloneConfiguration.setPort(6379);
        return new JedisConnectionFactory(redisStandaloneConfiguration, getJedisClientConfiguration());
    }

    @Bean
    public RedisTemplate getRedisTemplate() {
        RedisTemplate redisTemplate = new RedisTemplate();
        redisTemplate.setConnectionFactory(getJedisConnectionFactory());
        return redisTemplate;
    }
}
@Service
public class TestService {
    @Autowired
    private RedisTemplate redisTemplate;

    public void setStringValue(String key, String value) {
        redisTemplate.opsForValue().set(key, value);
    }

    public String getStringValue(String key) {
        return redisTemplate.opsForValue().get(key);
    }
}
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.*;
import vip.fkandy.redis.service.TestService;

@ComponentScan
public class Application {
    public static void main(String[] args) {
        ApplicationContext context =
                new AnnotationConfigApplicationContext(Application.class);
        TestService testService = context.getBean(TestService.class);
        testService.setStringValue("1","123");
        System.out.println(testService.getStringValue("1"));
    }
}  
#最大活动对象数       
redis.pool.maxTotal=1000      
#最大能够保持idel状态的对象数        
redis.pool.maxIdle=100    
#最小能够保持idel状态的对象数     
redis.pool.minIdle=50      
#当池内没有返回对象时,最大等待时间      
redis.pool.maxWaitMillis=10000      
#当调用borrow Object方法时,是否进行有效性检查      
redis.pool.testOnBorrow=true      
#当调用return Object方法时,是否进行有效性检查      
redis.pool.testOnReturn=true    
#“空闲链接”检测线程,检测的周期,毫秒数。如果为负值,表示不运行“检测线程”。默认为-1.    
redis.pool.timeBetweenEvictionRunsMillis=30000    
#向调用者输出“链接”对象时,是否检测它的空闲超时;    
redis.pool.testWhileIdle=true    
# 对于“空闲链接”检测线程而言,每次检测的链接资源的个数。默认为3.    
redis.pool.numTestsPerEvictionRun=50  




你可能感兴趣的:(Spring-data-redis (2.0.5) 单机版)