Spring Data Redis Configuration class Redisconfig

Source: Internet
Author: User
Tags connection pooling

 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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.