Skip to content

Commit

Permalink
feat: Added config option to specific protocol version. Resolves #7
Browse files Browse the repository at this point in the history
  • Loading branch information
Julien Ruaux committed Jan 5, 2023
1 parent d9205e7 commit 6dc5c64
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 5 deletions.
4 changes: 4 additions & 0 deletions src/docs/asciidoc/index.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,10 @@ redisearch.uri=redis://localhost:6379
|Connect to a Redis Cluster.
|`false`

|`redisearch.resp2`
|Force Redis protocol version to RESP2.
|`false`

|===

The RediSearch connector provides additional security options to support Redis servers with TLS mode.
Expand Down
12 changes: 12 additions & 0 deletions src/main/java/com/redis/trino/RediSearchConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ public class RediSearchConfig {
private String keyPath;
private String certPath;
private String keyPassword;
private boolean resp2;

@Min(0)
public long getCursorCount() {
Expand Down Expand Up @@ -91,6 +92,17 @@ public RediSearchConfig setCaseInsensitiveNames(boolean caseInsensitiveNames) {
return this;
}

public boolean isResp2() {
return resp2;
}

@Config("redisearch.resp2")
@ConfigDescription("Force Redis protocol version to RESP2")
public RediSearchConfig setResp2(boolean resp2) {
this.resp2 = resp2;
return this;
}

@Config("redisearch.table-cache-expiration")
@ConfigDescription("Duration in seconds since the entry creation after which a table should be automatically removed from the cache.")
public RediSearchConfig setTableCacheExpiration(long expirationDuration) {
Expand Down
4 changes: 4 additions & 0 deletions src/main/java/com/redis/trino/RediSearchSession.java
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@
import io.lettuce.core.AbstractRedisClient;
import io.lettuce.core.RedisURI;
import io.lettuce.core.SslVerifyMode;
import io.lettuce.core.protocol.ProtocolVersion;
import io.trino.spi.HostAddress;
import io.trino.spi.TrinoException;
import io.trino.spi.connector.ColumnMetadata;
Expand Down Expand Up @@ -122,6 +123,9 @@ private AbstractRedisClient client(RediSearchConfig config) {
config.getCertPath().map(File::new).ifPresent(builder::keyCert);
config.getKeyPassword().ifPresent(p -> builder.keyPassword(p.toCharArray()));
config.getCaCertPath().map(File::new).ifPresent(builder::trustManager);
if (config.isResp2()) {
builder.protocolVersion(ProtocolVersion.RESP2);
}
return builder.build();
}

Expand Down
11 changes: 6 additions & 5 deletions src/test/java/com/redis/trino/TestRediSearchConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@

import static io.airlift.configuration.testing.ConfigAssertions.assertRecordedDefaults;
import static io.airlift.configuration.testing.ConfigAssertions.recordDefaults;
import static org.testng.Assert.assertEquals;

import java.util.Map;

import org.testng.Assert;
import org.testng.annotations.Test;

import com.google.common.collect.ImmutableMap;
Expand All @@ -17,7 +17,7 @@ public class TestRediSearchConfig {
@Test
public void testDefaults() {
assertRecordedDefaults(recordDefaults(RediSearchConfig.class).setUri(null).setInsecure(false).setUsername(null)
.setPassword(null).setDefaultSchema(RediSearchConfig.DEFAULT_SCHEMA)
.setResp2(false).setPassword(null).setDefaultSchema(RediSearchConfig.DEFAULT_SCHEMA)
.setDefaultLimit(RediSearchConfig.DEFAULT_LIMIT).setCaseInsensitiveNames(false)
.setCursorCount(RediSearchConfig.DEFAULT_CURSOR_COUNT)
.setTableCacheExpiration(RediSearchConfig.DEFAULT_TABLE_CACHE_EXPIRATION.toSeconds())
Expand All @@ -30,15 +30,16 @@ public void testExplicitPropertyMappings() {
String uri = "redis://redis.example.com:12000";
String defaultSchema = "myschema";
Map<String, String> properties = new ImmutableMap.Builder<String, String>().put("redisearch.uri", uri)
.put("redisearch.default-schema-name", defaultSchema).build();
.put("redisearch.default-schema-name", defaultSchema).put("redisearch.resp2", "true").build();

ConfigurationFactory configurationFactory = new ConfigurationFactory(properties);
RediSearchConfig config = configurationFactory.build(RediSearchConfig.class);

RediSearchConfig expected = new RediSearchConfig().setDefaultSchema(defaultSchema).setUri(uri);

assertEquals(config.getDefaultSchema(), expected.getDefaultSchema());
assertEquals(config.getUri(), expected.getUri());
Assert.assertEquals(config.getDefaultSchema(), expected.getDefaultSchema());
Assert.assertEquals(config.getUri(), expected.getUri());
Assert.assertTrue(config.isResp2());
}

}

0 comments on commit 6dc5c64

Please sign in to comment.