开发者社区> 问答> 正文

阿里与Redis 利用redis实现session共享

报错如下: [Spring session redis executor thread: 1] ERROR org.springframework.data.redis.listener.RedisMessageListenerContainer - Connection failure occurred.

@Configuration
@EnableRedisHttpSession(maxInactiveIntervalInSeconds = 36000)
public class RedisConfig {

    @Value("${spring.redis.host}")
    private String host;
    @Value("${spring.redis.port}")
    private int port;
    @Value("${spring.redis.password}")
    private String password;

    @Bean
    public JedisPool jedisPool(JedisPoolConfig jedisPoolConfig){
        System.out.println("redis相关信息"+host+port);
        JedisPool jedisPool = new JedisPool(jedisPoolConfig,host,port,5000,password);

        return jedisPool;
    }

    @Bean
    public JedisPoolConfig jedisPoolConfig(){
        JedisPoolConfig jedisPoolConfig = new JedisPoolConfig();
        jedisPoolConfig.setMinIdle(10);
        jedisPoolConfig.setMaxIdle(100);
        jedisPoolConfig.setMaxTotal(1000);
        return jedisPoolConfig;
    }



    /**
     *  解决redis集群环境没有开启Keyspace notifications导致的
     *
     *  Error creating bean with name 'enableRedisKeyspaceNotificationsInitializer' defined in class path resource
     *
     * */
    @Bean
    public static ConfigureRedisAction configureRedisAction() {

        return ConfigureRedisAction.NO_OP;
    }



    /**
     * 用于spring session,防止每次创建一个线程
     * @return
     */
    @Bean
    public ThreadPoolTaskExecutor springSessionRedisTaskExecutor() {
        ThreadPoolTaskExecutor springSessionRedisTaskExecutor = new ThreadPoolTaskExecutor();
        springSessionRedisTaskExecutor.setCorePoolSize(8);
        springSessionRedisTaskExecutor.setMaxPoolSize(16);
        springSessionRedisTaskExecutor.setKeepAliveSeconds(10);
        springSessionRedisTaskExecutor.setQueueCapacity(1000);
        springSessionRedisTaskExecutor.setThreadNamePrefix("Spring session redis executor thread: ");
        return springSessionRedisTaskExecutor;
    }

}

遇到了同样的问题,在CSDN看到了,希望阿里云团队能够给出正确、标准的答案~请查看

展开
收起
刘刚_ 2020-05-22 21:38:31 1137 0
1 条回答
写回答
取消 提交回答
  • 你好,问题已转交阿里云Goc团队,敬请期待

    2020-05-22 21:58:37
    赞同 展开评论 打赏
问答排行榜
最热
最新

相关电子书

更多
Redis在唯品会的应用实践——架构演进与功能定制 立即下载
微博的Redis定制之路 立即下载
云数据库Redis版的开源之路 立即下载