我的 pom
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-mongodb-reactive</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-redis-reactive</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-webflux</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.session</groupId>
<artifactId>spring-session-data-redis</artifactId>
</dependency>
application.properties
spring.data.mongodb.uri=mongodb://localhost:27017/apitest
spring.jackson.time-zone=GMT+8
spring.redis.host=localhost
spring.redis.database=1
spring.redis.port=6379
spring.session.store-type=redis
我发现我运行后,始终只出现在 database=0 有数据,database=1 是空的
1
leriou 2018-10-24 12:51:16 +08:00
跟 pom 没关系吧, 先 select db,每个 db 写两条数据看看, 再测试, redis 里面如果本来其他 db 就没有数据有啥用, redis 集群的话也用不了 db
|
2
shayang888 OP @leriou application.properties 里的配置我都没变过 就 pom 里 redis 改成了 reactive 的,boot starter 改成了 webflux 的 之前的旧的我改成几数据就在几里 这个新特性就变成这样了
|
3
wowo243 2018-10-24 13:00:50 +08:00 via Android
看源码呗,这里问有啥用
|
4
xgfan 2018-10-24 13:43:59 +08:00 via iPhone
看下那几个 autoconfig 的源码就好了
|
5
artist 2018-10-24 15:12:02 +08:00 1
JedisConnectionFactory
/** * Sets the index of the database used by this connection factory. Default is 0. * * @param index database index. * @deprecated since 2.0, configure the client name using {@link RedisSentinelConfiguration} or * {@link RedisStandaloneConfiguration}. */ @Deprecated public void setDatabase(int index) { Assert.isTrue(index >= 0, "invalid DB index (a positive index required)"); if (isRedisSentinelAware()) { sentinelConfig.setDatabase(index); return; } standaloneConfig.setDatabase(index); } |
6
shayang888 OP @artist 我按你说的,专门创建了个 config 类来设置 database 也没用 我 redis 里 select 1 keys "*"返回的还是空的,数据都在 0 里面
|
7
shayang888 OP @artist 解决了 谢谢
|
8
2yug 2019-02-28 10:05:21 +08:00
你好,能说下怎么解决的嘛,我也遇到这个问题了~
|
9
shayang888 OP @2yug
``` @Configuration @EnableRedisWebSession public class RedisSessionConfig { @Value("${spring.redis.database}") private int database; @Bean public ReactiveRedisConnectionFactory redisConnectionFactory() { RedisSentinelConfiguration redisSentinelConfiguration = new RedisSentinelConfiguration(); redisSentinelConfiguration.setDatabase(database); return new LettuceConnectionFactory(redisSentinelConfiguration); } } ``` |
10
2yug 2019-02-28 18:39:21 +08:00
@shayang888
按你的配置了还是不行,哎! |
11
2yug 2019-03-01 11:21:45 +08:00
@shayang888 我把 springboot 版本升级成 2.1.3 (之前是 2.0.0 )就可以了!!!没有加其他配置,只在 properties 里面指定了 datebase。
|
12
shayang888 OP |
13
2yug 2019-03-01 14:05:49 +08:00
@shayang888 嗯,这个我知道,但是我现在没加你发的配置也可以了~
|