Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,9 @@ private JedisClientConfigurationBuilder applyProperties(JedisClientConfiguration
Duration timeout = getProperties().getTimeout();
builder.readTimeout(timeout).connectTimeout(timeout);
}
if (StringUtils.hasText(getProperties().getClientName())) {
builder.clientName(getProperties().getClientName());
}
return builder;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,9 @@ private LettuceClientConfigurationBuilder applyProperties(
builder.shutdownTimeout(getProperties().getLettuce().getShutdownTimeout());
}
}
if (StringUtils.hasText(getProperties().getClientName())) {
builder.clientName(getProperties().getClientName());
}
return builder;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,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;
Expand Down Expand Up @@ -134,6 +139,14 @@ public Duration getTimeout() {
return this.timeout;
}

public String getClientName() {
return this.clientName;
}

public void setClientName(String clientName) {
this.clientName = clientName;
}

public Sentinel getSentinel() {
return this.sentinel;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,16 @@ public void testRedisConfigurationWithTimeout() {
});
}

@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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,16 @@ void testRedisConfigurationWithTimeout() {
});
}

@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");
Expand Down