Skip to content

Commit

Permalink
feat!: Changed key prefix to application name
Browse files Browse the repository at this point in the history
Resolves #9
  • Loading branch information
Julien Ruaux committed Mar 30, 2023
1 parent 2395948 commit 3e09d46
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 36 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ public static KeyBuilder keyBuilder(Config config, String prefix) {
}

private static KeyBuilder keyBuilder(Config config) {
return new KeyBuilder(config.getRedis().getKey().getPrefix(), config.getRedis().getKey().getSeparator());
return new KeyBuilder(config.getName(), config.getRedis().getKeySeparator());
}

private AbstractRedisClient client(Config config) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,23 @@

public class Config {

public static final String DEFAULT_NAME = "smartcache";

private String name = DEFAULT_NAME;
private DriverConfig driver = new DriverConfig();
private RedisConfig redis = new RedisConfig();
private RulesetConfig ruleset = new RulesetConfig();
private MetricsConfig metrics = new MetricsConfig();
private AnalyzerConfig analyzer = new AnalyzerConfig();

public String getName() {
return name;
}

public void setName(String name) {
this.name = name;
}

public DriverConfig getDriver() {
return driver;
}
Expand Down Expand Up @@ -64,7 +75,7 @@ public void setAnalyzer(AnalyzerConfig analyzer) {

@Override
public int hashCode() {
return Objects.hash(redis.getUri(), redis.getKey().getPrefix());
return Objects.hash(redis.getUri(), name);
}

@Override
Expand All @@ -76,33 +87,7 @@ public boolean equals(Object obj) {
if (getClass() != obj.getClass())
return false;
Config other = (Config) obj;
return Objects.equals(redis.getUri(), other.redis.getUri())
&& Objects.equals(redis.key.getPrefix(), other.redis.key.prefix);
}

public static class KeyConfig {

public static final String DEFAULT_PREFIX = "smartcache";

private String prefix = DEFAULT_PREFIX;
private String separator = KeyBuilder.DEFAULT_SEPARATOR;

public String getPrefix() {
return prefix;
}

public void setPrefix(String prefix) {
this.prefix = prefix;
}

public String getSeparator() {
return separator;
}

public void setSeparator(String separator) {
this.separator = separator;
}

return Objects.equals(redis.getUri(), other.redis.getUri()) && Objects.equals(name, other.name);
}

public static class MetricsConfig {
Expand Down Expand Up @@ -143,8 +128,8 @@ public static class RedisConfig {
private SslVerifyMode tlsVerify = SslVerifyMode.NONE;
private String username;
private char[] password;
private KeyConfig key = new KeyConfig();
private DataSize codecBufferCapacity = DEFAULT_BUFFER_CAPACITY;
private String keySeparator = KeyBuilder.DEFAULT_SEPARATOR;

/**
*
Expand All @@ -162,12 +147,12 @@ public void setCodecBufferSizeInBytes(long size) {
this.codecBufferCapacity = DataSize.ofBytes(size);
}

public KeyConfig getKey() {
return key;
public String getKeySeparator() {
return keySeparator;
}

public void setKey(KeyConfig key) {
this.key = key;
public void setKeySeparator(String keySeparator) {
this.keySeparator = keySeparator;
}

public boolean isTls() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
import com.redis.lettucemod.RedisModulesClient;
import com.redis.lettucemod.api.StatefulRedisModulesConnection;
import com.redis.smartcache.Driver;
import com.redis.smartcache.core.Config.KeyConfig;
import com.redis.smartcache.core.Config.RuleConfig;
import com.redis.smartcache.core.Config.RulesetConfig;
import com.redis.testcontainers.RedisStackContainer;
Expand All @@ -40,7 +39,7 @@ void keyBuilder() {
Config config = new Config();
KeyBuilder keyBuilder = Driver.keyBuilder(config, Driver.KEYSPACE_CACHE);
String id = "123";
Assertions.assertEquals(KeyConfig.DEFAULT_PREFIX + KeyBuilder.DEFAULT_SEPARATOR + Driver.KEYSPACE_CACHE
Assertions.assertEquals(Config.DEFAULT_NAME + KeyBuilder.DEFAULT_SEPARATOR + Driver.KEYSPACE_CACHE
+ KeyBuilder.DEFAULT_SEPARATOR + id, keyBuilder.create(id));
}

Expand Down

0 comments on commit 3e09d46

Please sign in to comment.