EzyRedis: Configuration
Updated at 2023-06-02 06:32:061. 1. Configuration List
EzyRedis provides a list of configurations in bellow table:2.
PropertyDefault ValueDescription1redis.atomic_long_map_name___ezydata.atomic_longs___Name of atomic long map2redis.mapsempty listList of redis map settings3redis.map_naming.caseNATUREMap name style. The map name will be class name by default4redis.map_naming.ignored_suffixnullSuffix to remove from map's name5redis.max_connection_attempts0Maximum retry connect times (this configuration is valid from version1.2.4
)6redis.channelsempty listList of redis channels3. 2. An Example
You can put bellow configuration to your application.yaml
file:
redis: uri: redis://localhost:6379 max_connection_attempts: 1000000 atomic_long_map_name: atomic_long_map map_naming: case: DASH ignored_suffix: true maps: map1: key_type: java.lang.String value_type: java.lang.Integer map2: key_type: java.lang.String value_type: java.lang.Integer channels: channel1: thread_pool_size: 2 message_type: java.lang.String channel2: thread_pool_size: 2 message_type: java.lang.String
Or you can put to your application.properties
file:
redis.uri=redis://localhost:6379 redis.max_connection_attempts=1000000 redis.atomic_long_map_name=atomic_long_map redis.map_naming.case=DASH redis.map_naming.ignored_suffix=true redis.maps.map1.key_type=java.lang.String redis.maps.map1.value_type=java.lang.Integer redis.maps.map2.key_type=java.lang.String redis.maps.map2.value_type=java.lang.Integer redis.channels.channel1.thread_pool_size=2 redis.channels.channel1.message_type=java.lang.String redis.channels.channel2.thread_pool_size=2 redis.channels.channel2.message_type=java.lang.String
4. 3. Auto Configuration
To configure automatically, you just need add configuration and add ezyfox-boot-autoconfigure
to your project dependency like this:
<dependency> <groupId>com.tvd12</groupId> <artifactId>ezyfox-boot-autoconfigure</artifactId> <version>1.1.1</version> </dependency>
5. 4. Configure Manually
For some reason, you can not use ezyfox-boot-autoconfigure
you can config like this:
import com.tvd12.ezydata.redis.EzyRedisClientPool; import com.tvd12.ezydata.redis.EzyRedisProxy; import com.tvd12.ezydata.redis.EzyRedisProxyFactory; import com.tvd12.ezydata.redis.loader.EzyJedisClientPoolLoader; import com.tvd12.ezyfox.bean.EzyBeanAutoConfig; import com.tvd12.ezyfox.bean.EzySingletonFactory; import com.tvd12.ezyfox.bean.EzySingletonFactoryAware; import com.tvd12.ezyfox.bean.annotation.EzyConfigurationBefore; import com.tvd12.ezyfox.util.EzyPropertiesAware; import lombok.Setter; import java.util.Properties; import java.util.Set; @Setter @EzyConfigurationBefore public class EzyRedisConfiguration implements EzyBeanConfig, EzyPropertiesAware, EzySingletonFactoryAware { private Properties properties; private EzySingletonFactory singletonFactory; @Override public void autoConfig() { singletonFactory.addSingleton("redisProxy", newRedisProxy()); } private EzyRedisProxy newRedisProxy() { return EzyRedisProxyFactory.builder() .properties(properties) .scan("your packages to scan") .clientPool(newClientPool()) .build() .newRedisProxy(); } protected EzyRedisClientPool newClientPool() { return new EzyJedisClientPoolLoader() .properties(properties) .load(); } }
6. 5. Configure Max Connection Attemps
There is a bug in version 1.2.3
, so for this version, you will need configure redis.max_connection_attempts
like this:
import com.tvd12.ezydata.redis.setting.EzyRedisSettings; import com.tvd12.ezyfox.bean.EzyBeanConfig; import com.tvd12.ezyfox.bean.annotation.EzyConfigurationBefore; import com.tvd12.ezyfox.util.EzyPropertiesAware; import lombok.Setter; @Setter @EzyConfigurationBefore(priority = Integer.MIN_VALUE) public class RedisConfig implements EzyPropertiesAware, EzyBeanConfig { private Properties properties; @Override public void config() { properties.put( EzyRedisSettings.MAX_CONNECTION_ATTEMPTS, Integer.parseInt( properties.getOrDefault( EzyRedisSettings.MAX_CONNECTION_ATTEMPTS, Integer.MAX_VALUE ).toString() ) ); } }