Add 'client-name' property to specify a Redis client name
See gh-17330
This commit is contained in:
parent
e496203740
commit
f877caf118
|
|
@ -94,6 +94,9 @@ class JedisConnectionConfiguration extends RedisConnectionConfiguration {
|
|||
Duration timeout = getProperties().getTimeout();
|
||||
builder.readTimeout(timeout).connectTimeout(timeout);
|
||||
}
|
||||
if (StringUtils.hasText(getProperties().getClientName())) {
|
||||
builder.clientName(getProperties().getClientName());
|
||||
}
|
||||
return builder;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -114,6 +114,9 @@ class LettuceConnectionConfiguration extends RedisConnectionConfiguration {
|
|||
builder.shutdownTimeout(getProperties().getLettuce().getShutdownTimeout());
|
||||
}
|
||||
}
|
||||
if (StringUtils.hasText(getProperties().getClientName())) {
|
||||
builder.clientName(getProperties().getClientName());
|
||||
}
|
||||
return builder;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -71,6 +71,11 @@ public class RedisProperties {
|
|||
*/
|
||||
private Duration timeout;
|
||||
|
||||
/**
|
||||
* Configure a clientName to be set with CLIENT SETNAME.
|
||||
*/
|
||||
private String clientName;
|
||||
|
||||
private Sentinel sentinel;
|
||||
|
||||
private Cluster cluster;
|
||||
|
|
@ -135,6 +140,14 @@ public class RedisProperties {
|
|||
return this.timeout;
|
||||
}
|
||||
|
||||
public String getClientName() {
|
||||
return this.clientName;
|
||||
}
|
||||
|
||||
public void setClientName(String clientName) {
|
||||
this.clientName = clientName;
|
||||
}
|
||||
|
||||
public Sentinel getSentinel() {
|
||||
return this.sentinel;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -134,6 +134,16 @@ public class RedisAutoConfigurationJedisTests {
|
|||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRedisConfigurationWithClientName() {
|
||||
this.contextRunner.withPropertyValues("spring.redis.host:foo", "spring.redis.client-name:spring-boot")
|
||||
.run((context) -> {
|
||||
JedisConnectionFactory cf = context.getBean(JedisConnectionFactory.class);
|
||||
assertThat(cf.getHostName()).isEqualTo("foo");
|
||||
assertThat(cf.getClientName()).isEqualTo("spring-boot");
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRedisConfigurationWithSentinel() {
|
||||
this.contextRunner
|
||||
|
|
|
|||
|
|
@ -160,6 +160,16 @@ class RedisAutoConfigurationTests {
|
|||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
void testRedisConfigurationWithClientName() {
|
||||
this.contextRunner.withPropertyValues("spring.redis.host:foo", "spring.redis.client-name:spring-boot")
|
||||
.run((context) -> {
|
||||
LettuceConnectionFactory cf = context.getBean(LettuceConnectionFactory.class);
|
||||
assertThat(cf.getHostName()).isEqualTo("foo");
|
||||
assertThat(cf.getClientName()).isEqualTo("spring-boot");
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
void testRedisConfigurationWithSentinel() {
|
||||
List<String> sentinels = Arrays.asList("127.0.0.1:26379", "127.0.0.1:26380");
|
||||
|
|
|
|||
Loading…
Reference in New Issue