Use RedisAutoConfiguration in RedisVectorStoreAutoConfiguration

Currently, `RedisVectorStoreAutoConfiguration` creates its own
configuration to connect with Redis. This commit reuse
`RedisAutoConfiguration` from spring boot project. It's limited
to Jedis.
This commit is contained in:
Eddú Meléndez
2024-07-16 15:44:59 -05:00
committed by Christian Tzolov
parent 40d8671f3e
commit 0a07f65d6a
19 changed files with 64 additions and 400 deletions

View File

@@ -1,61 +0,0 @@
/*
* Copyright 2023 - 2024 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.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.ai.docker.compose.service.connection.redis;
import org.springframework.ai.autoconfigure.vectorstore.redis.RedisConnectionDetails;
import org.springframework.boot.docker.compose.core.RunningService;
import org.springframework.boot.docker.compose.service.connection.DockerComposeConnectionDetailsFactory;
import org.springframework.boot.docker.compose.service.connection.DockerComposeConnectionSource;
/**
* @author Eddú Meléndez
*/
class RedisDockerComposeConnectionDetailsFactory extends DockerComposeConnectionDetailsFactory<RedisConnectionDetails> {
private static final String[] REDIS_IMAGE_NAMES = { "redis/redis-stack", "redis/redis-stack-server" };
private static final int REDIS_PORT = 6379;
protected RedisDockerComposeConnectionDetailsFactory() {
super(REDIS_IMAGE_NAMES);
}
@Override
protected RedisConnectionDetails getDockerComposeConnectionDetails(DockerComposeConnectionSource source) {
return new RedisDockerComposeConnectionDetails(source.getRunningService());
}
/**
* {@link RedisConnectionDetails} backed by a {@code Redis} {@link RunningService}.
*/
static class RedisDockerComposeConnectionDetails extends DockerComposeConnectionDetails
implements RedisConnectionDetails {
private final String uri;
RedisDockerComposeConnectionDetails(RunningService service) {
super(service);
this.uri = "redis://" + service.host() + ":" + service.ports().get(REDIS_PORT);
}
@Override
public String getUri() {
return this.uri;
}
}
}

View File

@@ -3,6 +3,5 @@ org.springframework.ai.docker.compose.service.connection.chroma.ChromaDockerComp
org.springframework.ai.docker.compose.service.connection.ollama.OllamaDockerComposeConnectionDetailsFactory,\
org.springframework.ai.docker.compose.service.connection.opensearch.OpenSearchDockerComposeConnectionDetailsFactory,\
org.springframework.ai.docker.compose.service.connection.qdrant.QdrantDockerComposeConnectionDetailsFactory,\
org.springframework.ai.docker.compose.service.connection.redis.RedisDockerComposeConnectionDetailsFactory,\
org.springframework.ai.docker.compose.service.connection.typesense.TypesenseDockerComposeConnectionDetailsFactory,\
org.springframework.ai.docker.compose.service.connection.weaviate.WeaviateDockerComposeConnectionDetailsFactory

View File

@@ -1,37 +0,0 @@
/*
* Copyright 2023 - 2024 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.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.ai.docker.compose.service.connection.redis;
import org.junit.jupiter.api.Test;
import org.springframework.ai.autoconfigure.vectorstore.redis.RedisConnectionDetails;
import org.springframework.boot.docker.compose.service.connection.test.AbstractDockerComposeIntegrationTests;
import org.testcontainers.utility.DockerImageName;
import static org.assertj.core.api.Assertions.assertThat;
class RedisStackDockerComposeConnectionDetailsFactoryTests extends AbstractDockerComposeIntegrationTests {
RedisStackDockerComposeConnectionDetailsFactoryTests() {
super("redis-compose.yaml", DockerImageName.parse("redis/redis-stack"));
}
@Test
void runCreatesConnectionDetails() {
RedisConnectionDetails connectionDetails = run(RedisConnectionDetails.class);
assertThat(connectionDetails.getUri()).startsWith("redis://");
}
}

View File

@@ -1,37 +0,0 @@
/*
* Copyright 2023 - 2024 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.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.ai.docker.compose.service.connection.redis;
import org.junit.jupiter.api.Test;
import org.springframework.ai.autoconfigure.vectorstore.redis.RedisConnectionDetails;
import org.springframework.boot.docker.compose.service.connection.test.AbstractDockerComposeIntegrationTests;
import org.testcontainers.utility.DockerImageName;
import static org.assertj.core.api.Assertions.assertThat;
class RedisStackServerDockerComposeConnectionDetailsFactoryTests extends AbstractDockerComposeIntegrationTests {
RedisStackServerDockerComposeConnectionDetailsFactoryTests() {
super("redis-compose.yaml", DockerImageName.parse("redis/redis-stack-server"));
}
@Test
void runCreatesConnectionDetails() {
RedisConnectionDetails connectionDetails = run(RedisConnectionDetails.class);
assertThat(connectionDetails.getUri()).startsWith("redis://");
}
}