Can't init enough connections amount! Only 0 from 10 were initialized. Server: IP:6379
无法初始化足够的连接数量!只有0和10被初始化。
vi redis.conf
注释:#bind 127.0.0.1
protected-mode yes 改成 protected-mode no
可能还是因为配置的连接池不够
我的原因的RedissonConfig配置的不够
package com.guige.core.conf; import io.netty.channel.nio.NioEventLoopGroup; import org.redisson.Config; import org.redisson.Redisson; import org.redisson.RedissonClient; import org.redisson.client.codec.Codec; import org.springframework.beans.factory.annotation.Value; import org.springframework.boot.context.properties.ConfigurationProperties; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.stereotype.Component; import org.springframework.util.ClassUtils; /** * Created by kl on 2017/09/26. * redisson 客户端配置 */ @Component @Configuration public class RedissonConfig { @Value("${spring.redis.host}") private String host; @Value("${spring.redis.port}") private Integer port; @Value("${spring.redis.password}") private String password; @Value("${spring.redis.pool.minidle}") private int connectionMinimumIdleSize = 10;//从节点最小空闲连接数) private int idleConnectionTimeout = 10000; private int pingTimeout = 1000; private int connectTimeout = 10000; @Value("${spring.redis.timeout}") private int timeout = 3000; private int retryAttempts = 3;//命令失败重试次数) private int retryInterval = 1500; //命令重试发送时间间隔,单位:毫秒) private int reconnectionTimeout = 3000;//重新连接时间间隔,单位:毫秒) private int failedAttempts = 3;//执行失败最大次数) private int subscriptionsPerConnection = 5;//单个连接最大订阅数量 private String clientName = null; //名称 @Value("${spring.redis.pool.minidle}") private int subscriptionConnectionMinimumIdleSize = 1; //从节点发布和订阅连接的最小空闲连接数) @Value("${spring.redis.pool.maxidle}") private int subscriptionConnectionPoolSize = 50; //(从节点发布和订阅连接池大小) @Value("${spring.redis.pool.maxidle}") private int connectionPoolSize = 64;//连接池大小) @Value("${spring.redis.database}") private int database = 0; private boolean dnsMonitoring = false;//是否启用DNS监测) private int dnsMonitoringInterval = 5000;//(DNS监测时间间隔,单位:毫秒) private int thread=0; //当前处理核数量 * 2 @Bean(destroyMethod = "shutdown") RedissonClient redissonClient() throws Exception { Config config = new Config(); config.useSingleServer().setAddress(host+":"+port) .setConnectionMinimumIdleSize(connectionMinimumIdleSize) .setConnectionPoolSize(connectionPoolSize) .setDatabase(database) .setDnsMonitoring(dnsMonitoring) .setDnsMonitoringInterval(dnsMonitoringInterval) .setSubscriptionConnectionMinimumIdleSize(subscriptionConnectionMinimumIdleSize) .setSubscriptionConnectionPoolSize(subscriptionConnectionPoolSize) .setSubscriptionsPerConnection(subscriptionsPerConnection) .setClientName(clientName) .setFailedAttempts(failedAttempts) .setRetryAttempts(retryAttempts) .setRetryInterval(retryInterval) .setReconnectionTimeout(reconnectionTimeout) .setTimeout(timeout) .setConnectTimeout(connectTimeout) .setIdleConnectionTimeout(idleConnectionTimeout) .setPingTimeout(pingTimeout) .setPassword(password); Codec codec = (Codec) ClassUtils.forName("org.redisson.codec.JsonJacksonCodec", ClassUtils.getDefaultClassLoader()).newInstance(); config.setCodec(codec); config.setThreads(thread); config.setEventLoopGroup(new NioEventLoopGroup()); config.setUseLinuxNativeEpoll(false); return Redisson.create(config); } }
spring: redis: database: 1 host: 192.168.1.161 port: 6379 timeout: 50000 password: 201805 pool: # 连接池最大连接数(使用负值表示没有限制) maxactive: 64 # 连接池中的最大空闲连接 maxidle: 64 # 连接池最大阻塞等待时间(使用负值表示没有限制) maxwait: -1 # 连接池中的最小空闲连接 minidle: 1
package com.guige.core.conf; import com.guige.core.ext.common.redis.MyCacheErrorHandler; import com.guige.core.ext.common.redis.MyKeyGenerator; import com.guige.core.ext.common.redis.MyRedisCacheManager; import com.guige.core.ext.common.redis.MyRedisTemplate; import org.springframework.beans.factory.annotation.Value; import org.springframework.cache.interceptor.CacheErrorHandler; import org.springframework.cache.interceptor.KeyGenerator; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.data.redis.cache.RedisCacheManager; import org.springframework.data.redis.connection.jedis.JedisConnectionFactory; import org.springframework.data.redis.core.RedisTemplate; import org.springframework.stereotype.Component; import redis.clients.jedis.JedisPoolConfig; /** * TODO * * @author songaw * @date 2018/7/17 11:29 */ @Component @Configuration public class RedisConf { @Value("${spring.redis.database}") private Integer database; @Value("${spring.redis.host}") private String host; @Value("${spring.redis.password}") private String password; @Value("${spring.redis.port}") private Integer port; @Value("${spring.redis.timeout}") private Integer timeout; @Value(value = "${spring.redis.expire:300}") private Integer expiration; @Value("${spring.redis.pool.maxactive}") private int maxActive; @Value("${spring.redis.pool.minidle}") private int minIdle; @Value("${spring.redis.pool.maxidle}") private int maxIdle; @Bean public JedisPoolConfig jedisPoolConfig(){ JedisPoolConfig poolConfig = new JedisPoolConfig(); poolConfig.setMaxIdle(this.maxIdle); poolConfig.setMinIdle(this.minIdle); poolConfig.setTestOnCreate(true); poolConfig.setTestOnBorrow(true); poolConfig.setTestOnReturn(true); poolConfig.setTestWhileIdle(true); return poolConfig; } @Bean public JedisConnectionFactory jedisConnectionFactory(){ JedisPoolConfig config = jedisPoolConfig(); JedisConnectionFactory jedisConnectionFactory = new JedisConnectionFactory(config); jedisConnectionFactory.setDatabase(this.database); jedisConnectionFactory.setHostName(this.host); jedisConnectionFactory.setPassword(this.password); jedisConnectionFactory.setPort(this.port); jedisConnectionFactory.setTimeout(this.timeout); return jedisConnectionFactory; } @Bean public RedisTemplate redisTemplate(){ MyRedisTemplate myRedisTemplate = new MyRedisTemplate(); myRedisTemplate.setConnectionFactory(jedisConnectionFactory()); return myRedisTemplate; } public RedisCacheManager redisCacheManager(){ MyRedisCacheManager myRedisCacheManager = new MyRedisCacheManager(redisTemplate()); return myRedisCacheManager; } @Bean public CacheErrorHandler cacheErrorHandler(){ MyCacheErrorHandler myCacheErrorHandler = new MyCacheErrorHandler(); return myCacheErrorHandler; } @Bean KeyGenerator keyGenerator(){ MyKeyGenerator myKeyGenerator = new MyKeyGenerator(); return myKeyGenerator; } }