Adapt to deprecations in Spring Data Redis

See gh-30200
pull/30328/merge
Andy Wilkinson 3 years ago
parent f693d7dfad
commit e60001fb16

@ -60,7 +60,7 @@ public class RedisHealthIndicator extends AbstractHealthIndicator {
RedisHealth.fromClusterInfo(builder, ((RedisClusterConnection) connection).clusterGetClusterInfo());
}
else {
RedisHealth.up(builder, connection.info("server"));
RedisHealth.up(builder, connection.serverCommands().info());
}
}

@ -30,6 +30,7 @@ import org.springframework.data.redis.connection.RedisClusterConnection;
import org.springframework.data.redis.connection.RedisClusterNode;
import org.springframework.data.redis.connection.RedisConnection;
import org.springframework.data.redis.connection.RedisConnectionFactory;
import org.springframework.data.redis.connection.RedisServerCommands;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.BDDMockito.given;
@ -51,7 +52,9 @@ class RedisHealthIndicatorTests {
Properties info = new Properties();
info.put("redis_version", "2.8.9");
RedisConnection redisConnection = mock(RedisConnection.class);
given(redisConnection.info("server")).willReturn(info);
RedisServerCommands serverCommands = mock(RedisServerCommands.class);
given(redisConnection.serverCommands()).willReturn(serverCommands);
given(serverCommands.info()).willReturn(info);
RedisHealthIndicator healthIndicator = createHealthIndicator(redisConnection);
Health health = healthIndicator.health();
assertThat(health.getStatus()).isEqualTo(Status.UP);
@ -61,7 +64,9 @@ class RedisHealthIndicatorTests {
@Test
void redisIsDown() {
RedisConnection redisConnection = mock(RedisConnection.class);
given(redisConnection.info("server")).willThrow(new RedisConnectionFailureException("Connection failed"));
RedisServerCommands serverCommands = mock(RedisServerCommands.class);
given(redisConnection.serverCommands()).willReturn(serverCommands);
given(serverCommands.info()).willThrow(new RedisConnectionFailureException("Connection failed"));
RedisHealthIndicator healthIndicator = createHealthIndicator(redisConnection);
Health health = healthIndicator.health();
assertThat(health.getStatus()).isEqualTo(Status.DOWN);

@ -158,7 +158,7 @@ class SessionAutoConfigurationRedisTests extends AbstractSessionAutoConfiguratio
assertThat(context.getBean(ConfigureRedisAction.class)).isInstanceOf(expectedConfigureRedisActionType);
RedisConnection connection = context.getBean(RedisConnectionFactory.class).getConnection();
if (expectedConfig.length > 0) {
assertThat(connection.getConfig("*")).contains(expectedConfig);
assertThat(connection.serverCommands().getConfig("*")).contains(expectedConfig);
}
};
}
@ -167,7 +167,7 @@ class SessionAutoConfigurationRedisTests extends AbstractSessionAutoConfiguratio
@Override
public void configure(RedisConnection connection) {
connection.setConfig("set-max-intset-entries", "1024");
connection.serverCommands().setConfig("set-max-intset-entries", "1024");
}
}

@ -1,5 +1,5 @@
/*
* Copyright 2012-2020 the original author or authors.
* Copyright 2012-2022 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -71,7 +71,7 @@ class DataRedisTestIntegrationTests {
assertThat(personHash.getId()).isNull();
PersonHash savedEntity = this.exampleRepository.save(personHash);
assertThat(savedEntity.getId()).isNotNull();
assertThat(this.operations.execute((RedisConnection connection) -> connection
assertThat(this.operations.execute((RedisConnection connection) -> connection.keyCommands()
.exists(("persons:" + savedEntity.getId()).getBytes(CHARSET)))).isTrue();
this.exampleRepository.deleteAll();
}

@ -1,5 +1,5 @@
/*
* Copyright 2012-2020 the original author or authors.
* Copyright 2012-2022 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -40,8 +40,8 @@ public class ExampleService {
}
public boolean hasRecord(PersonHash personHash) {
return this.operations.execute(
(RedisConnection connection) -> connection.exists(("persons:" + personHash.getId()).getBytes(CHARSET)));
return this.operations.execute((RedisConnection connection) -> connection.keyCommands()
.exists(("persons:" + personHash.getId()).getBytes(CHARSET)));
}
}

Loading…
Cancel
Save