Workaround for unable to modify DB in Jedisshardinfo

Source: Internet
Author: User

 PackageCom.ldr.bean;ImportJava.lang.reflect.Field;ImportRedis.clients.jedis.JedisShardInfo; Public classMyjedisinfo {String host; intPort; intDB;  PublicJedisshardinfo newinstance ()throwsnosuchfieldexception, SecurityException, IllegalArgumentException, illegalaccessexception {JedisShardInfo J Edisshardinfo=NewJedisshardinfo (Host,port); Class<?extendsjedisshardinfo> CLZ =Jedisshardinfo.getclass (); Field Declaredfield= Clz.getdeclaredfield ("DB"); Declaredfield.setaccessible (true);        Declaredfield.set (jedisshardinfo, DB); returnJedisshardinfo; }     PublicString gethost () {returnhost; }     Public voidSethost (String host) { This. Host =host; }     Public intGetdb () {returnDB; }     Public voidSetdb (intdb) {         This. db =DB; }     Public intGetport () {returnPort; }     Public voidSetport (intPort) {         This. Port =Port; }  }

The Application.xml in spring are configured as follows

        <!--Spring Integrated Redis -    <BeanID= "Jedispoolconfig"class= "Redis.clients.jedis.JedisPoolConfig">        < Propertyname= "Maxtotal">        <value>${redis.maxtotal}</value>        </ Property>        < Propertyname= "Maxidle">         <value>${redis.maxidle}</value>        </ Property>        < Propertyname= "Testonborrow"value= "true"/>        < Propertyname= "Testonreturn"value= "true"/>    </Bean>        <BeanID= "Shardedjedispool"class= "Redis.clients.jedis.ShardedJedisPool"Scope= "Singleton">        <Constructor-argIndex= "0"ref= "Jedispoolconfig" />        <Constructor-argIndex= "1">            <List>                <!--<bean class= "Redis.clients.jedis.JedisShardInfo" > <constructor-arg name= "host" value= "${r Edis.host} "/> <constructor-arg name=" port "value=" ${redis.port} "/> </bean& Gt  -                          <refBean= "Jedisshardinfo"/><!--production environment, please replace the above -            </List>        </Constructor-arg>    </Bean>        <!--The following configuration on production please comment out the BEGIN -    <BeanID= "Jedisfactory"class= "Com.ldr.bean.MyJedisInfo">        < Propertyname= "Host"value= "${redis.host}"></ Property>        < Propertyname= "Port"value= "${redis.port}"></ Property>        < Propertyname= "db"value= "${redis.db}"></ Property>    </Bean>           <BeanID= "Jedisshardinfo"class= "Redis.clients.jedis.JedisShardInfo"Factory-bean= "Jedisfactory"Factory-method= "Newinstance" >      </Bean>      <!--above configuration on production please comment out end -

Workaround for unable to modify DB in Jedisshardinfo

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.