主从哨兵模式,配置readFromSlave:true,需要配置slaves,这块配置找了下文档都没提及,看源码似乎是在slaves下配置,试着配了一下加载配置有错误,配置内容:
部署配置环境master在192.168.1.106 6379,slave在192.168.1.106:6380, sentinel在192.168.1.106:26379
jetcache:
remote:
default:
host: 192.168.1.106
port: 6379
password: 123
timeout: 3000
masterName: mymaster
sentinels: 192.168.1.106:26379
readFromSlave: true
slaves:
slave1:
host: 192.168.1.106
port: 6379
password: 123
timeout: 3000
加载配置有这样的错误:
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'redisAutoInit' defined in class path resource [com/alicp/jetcache/autoconfigure/RedisAutoConfiguration.class]: Invocation of init method failed; nested exception is com.alicp.jetcache.CacheConfigException: parse poolConfig fail
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1796)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:595)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:517)
at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:323)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:321)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:202)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:310)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:227)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveNamedBean(DefaultListableBeanFactory.java:1158)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveBean(DefaultListableBeanFactory.java:419)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBean(DefaultListableBeanFactory.java:349)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBean(DefaultListableBeanFactory.java:342)
at com.alicp.jetcache.anno.field.CreateCacheWrapper.init(CreateCacheWrapper.java:45)
at com.alicp.jetcache.anno.field.CreateCacheWrapper.<init>(CreateCacheWrapper.java:41)
at com.alicp.jetcache.anno.field.CreateCacheAnnotationBeanPostProcessor$AutowiredFieldElement.inject(CreateCacheAnnotationBeanPostProcessor.java:181)
at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:130)
at com.alicp.jetcache.anno.field.CreateCacheAnnotationBeanPostProcessor.postProcessProperties(CreateCacheAnnotationBeanPostProcessor.java:64)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1422)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:594)
... 62 more
Caused by: com.alicp.jetcache.CacheConfigException: parse poolConfig fail
at com.alicp.jetcache.autoconfigure.RedisAutoConfiguration$RedisAutoInit.parsePoolConfig(RedisAutoConfiguration.java:169)
at com.alicp.jetcache.autoconfigure.RedisAutoConfiguration$RedisAutoInit.parsePool(RedisAutoConfiguration.java:93)
at com.alicp.jetcache.autoconfigure.RedisAutoConfiguration$RedisAutoInit.initCache(RedisAutoConfiguration.java:72)
at com.alicp.jetcache.autoconfigure.AbstractCacheAutoInit.process(AbstractCacheAutoInit.java:66)
at com.alicp.jetcache.autoconfigure.AbstractCacheAutoInit.afterPropertiesSet(AbstractCacheAutoInit.java:47)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1855)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1792)
... 81 more
Caused by: java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at com.alicp.jetcache.autoconfigure.RedisAutoConfiguration$RedisAutoInit.parsePoolConfig(RedisAutoConfiguration.java:149)
... 87 more
Caused by: java.util.NoSuchElementException: No value bound
at org.springframework.boot.context.properties.bind.BindResult.get(BindResult.java:56)
... 92 more
看了下是找不到slave1.poolconfig,可能是配置的方式不对,请问下如何配置
3条答案
按热度按时间6mzjoqzu1#
jedis没支持sentinel的情况下从slave读
cmssoen22#
那么是非sentinel情况系的主从可以从slave读取吗,文档没看到示例,自己配了报错,主要是想请教下这块如何配置
46qrfjad3#
可以参考这里: https://github.com/alibaba/jetcache/blob/master/jetcache-test/src/test/resources/config/application-redis.yml