Skip to content
Open
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 @@ -16,6 +16,8 @@

package org.springframework.ai.model.chat.memory.repository.redis.autoconfigure;

import redis.clients.jedis.DefaultJedisClientConfig;
import redis.clients.jedis.JedisClientConfig;
import redis.clients.jedis.RedisClient;

import org.springframework.ai.chat.memory.ChatMemory;
Expand Down Expand Up @@ -71,6 +73,15 @@ public RedisChatMemoryRepositoryProperties redisChatMemoryRepositoryProperties(E
@Bean
@ConditionalOnMissingBean
public RedisClient jedisClient(RedisChatMemoryRepositoryProperties properties) {
if (StringUtils.hasText(properties.getPassword())) {
JedisClientConfig clientConfig = DefaultJedisClientConfig.builder()
.password(properties.getPassword())
.build();
return RedisClient.builder()
.hostAndPort(properties.getHost(), properties.getPort())
.clientConfig(clientConfig)
.build();
}
return RedisClient.builder().hostAndPort(properties.getHost(), properties.getPort()).build();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,11 @@ public class RedisChatMemoryRepositoryProperties {
*/
private int port = 6379;

/**
* Redis server password.
*/
private @Nullable String password;

/**
* Name of the Redis search index.
*/
Expand Down Expand Up @@ -103,6 +108,14 @@ public void setPort(int port) {
this.port = port;
}

public @Nullable String getPassword() {
return this.password;
}

public void setPassword(@Nullable String password) {
this.password = password;
}

public String getIndexName() {
return this.indexName;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,16 @@ public void setPort(int port) {
this.delegate.setPort(port);
}

@DeprecatedConfigurationProperty(replacement = "spring.ai.chat.memory.repository.redis.password")
@Deprecated(since = "2.0.1", forRemoval = true)
public @Nullable String getPassword() {
return this.delegate.getPassword();
}

public void setPassword(@Nullable String password) {
this.delegate.setPassword(password);
}

@DeprecatedConfigurationProperty(replacement = "spring.ai.chat.memory.repository.redis.index-name")
@Deprecated(since = "2.0.1", forRemoval = true)
public String getIndexName() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,4 +68,29 @@ void propertiesWithNewPrefix() {
});
}

@Test
void passwordWithOldPrefix() {
this.contextRunner
.withPropertyValues("spring.ai.chat.memory.redis.host=10.0.0.1", "spring.ai.chat.memory.redis.port=6380",
"spring.ai.chat.memory.redis.password=secret",
"spring.ai.chat.memory.redis.initialize-schema=false")
.run(context -> {
var chatProperties = context.getBean(RedisChatMemoryRepositoryProperties.class);
assertThat(chatProperties.getPassword()).isEqualTo("secret");
});
}

@Test
void passwordWithNewPrefix() {
this.contextRunner
.withPropertyValues("spring.ai.chat.memory.repository.redis.host=10.0.0.1",
"spring.ai.chat.memory.repository.redis.port=6380",
"spring.ai.chat.memory.repository.redis.password=secret",
"spring.ai.chat.memory.repository.redis.initialize-schema=false")
.run(context -> {
var chatProperties = context.getBean(RedisChatMemoryRepositoryProperties.class);
assertThat(chatProperties.getPassword()).isEqualTo("secret");
});
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -522,6 +522,7 @@ ChatMemory chatMemory = MessageWindowChatMemory.builder()
|Property | Description | Default Value
| `spring.ai.chat.memory.repository.redis.host` | Redis server host | `localhost`
| `spring.ai.chat.memory.repository.redis.port` | Redis server port | `6379`
| `spring.ai.chat.memory.repository.redis.password` | Redis server password | _none_
| `spring.ai.chat.memory.repository.redis.index-name` | Name of the Redis search index | `chat-memory-idx`
| `spring.ai.chat.memory.repository.redis.key-prefix` | Key prefix for chat memory entries | `chat-memory:`
| `spring.ai.chat.memory.repository.redis.time-to-live` | Time to live for chat memory entries (e.g., `24h`, `30d`) | _no expiration_
Expand Down
Loading