PackageCom.tz.config;ImportOrg.springframework.context.annotation.Bean;Importorg.springframework.context.annotation.Configuration;Importorg.springframework.data.redis.connection.jedis.JedisConnectionFactory;Importorg.springframework.data.redis.core.RedisTemplate;ImportOrg.springframework.data.redis.serializer.StringRedisSerializer;ImportRedis.clients.jedis.JedisPoolConfig;/*** This class completes some configuration of redis consolidation <br/> * * <li> Connection Pool </li> * <li> Factory </li> * <li> Redistemplate: How to operate the Redis method </li>*/@Configuration Public classRedisconfig {/*** Configure connection Pooling * 1. Create a Jedispoolconfig object*/@Bean//Springboot to manage, configuration files <bean> similar Publicjedispoolconfig Getjedispoolconfig () {jedispoolconfig config=NewJedispoolconfig (); //Configure maximum number of idleConfig.setmaxidle (10); //Configuration and minimum number of idleConfig.setminidle (5); //Configure the maximum number of connectionsConfig.setmaxtotal (20); returnconfig; } /*** 2. Create jedisconnectionfactory, configure Redis connection information **/@Bean Publicjedisconnectionfactory jedisconnectiofactory (jedispoolconfig config) {jedisconnectionfactory factory=Newjedisconnectionfactory (); //configuration object for the associated connection poolfactory.setpoolconfig (config); //configuring information to connect to RedisFactory.sethostname ("192.168.93.128"); Factory.setport (6379); returnFactory; } /*** 3. Create Redistemplate: Methods for performing Redis operations*/@Bean PublicRedistemplate<string, object>redistemplate (Jedisconnectionfactory factory) {redistemplate<String,Object> template=NewRedistemplate<string, object>(); Template.setconnectionfactory (Factory); //set the serializer for keyTemplate.setkeyserializer (NewStringredisserializer ()); //set the serializer for valueTemplate.setvalueserializer (NewStringredisserializer ()); returntemplate; } }
Spring Data Redis Configuration class Redisconfig