-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
be6cba7
commit b7641fc
Showing
19 changed files
with
895 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
71 changes: 71 additions & 0 deletions
71
core/redis-smart-cache-core/src/main/java/com/redis/smartcache/core/Query.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
package com.redis.smartcache.core; | ||
|
||
import java.util.Set; | ||
|
||
public class Query { | ||
|
||
private String id; | ||
private String sql; | ||
private Set<String> tables; | ||
|
||
public Query(){ | ||
} | ||
private Query(QueryBuilder builder) { | ||
this.id = builder.id; | ||
this.sql = builder.sql; | ||
this.tables = builder.tables; | ||
} | ||
|
||
public String getId() { | ||
return id; | ||
} | ||
|
||
public void setId(String id) { | ||
this.id = id; | ||
} | ||
|
||
public String getSql() { | ||
return sql; | ||
} | ||
|
||
public void setSql(String sql) { | ||
this.sql = sql; | ||
} | ||
|
||
public Set<String> getTables() { | ||
return tables; | ||
} | ||
|
||
public void setTables(Set<String> tables) { | ||
this.tables = tables; | ||
} | ||
|
||
public static class QueryBuilder { | ||
private String id; | ||
private String sql; | ||
private Set<String> tables; | ||
|
||
public QueryBuilder() {} | ||
|
||
public QueryBuilder setId(String id) { | ||
this.id = id; | ||
return this; | ||
} | ||
|
||
public QueryBuilder setSql(String sql) { | ||
this.sql = sql; | ||
return this; | ||
} | ||
|
||
public QueryBuilder setTables(Set<String> tables) { | ||
this.tables = tables; | ||
return this; | ||
} | ||
|
||
public Query build() { | ||
return new Query(this); | ||
} | ||
} | ||
|
||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 0 additions & 35 deletions
35
core/redis-smart-cache-jdbc/src/main/java/com/redis/smartcache/jdbc/Query.java
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
54 changes: 54 additions & 0 deletions
54
tools/redis-smart-cache-cli/src/main/java/com/redis/smartcache/cli/RedisConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
package com.redis.smartcache.cli; | ||
|
||
import com.redis.lettucemod.RedisModulesClient; | ||
import com.redis.lettucemod.api.StatefulRedisModulesConnection; | ||
import com.redis.smartcache.core.ClientManager; | ||
import com.redis.smartcache.core.Config; | ||
import io.lettuce.core.AbstractRedisClient; | ||
import io.lettuce.core.RedisClient; | ||
import io.lettuce.core.api.StatefulRedisConnection; | ||
import org.springframework.beans.factory.annotation.Value; | ||
import org.springframework.boot.autoconfigure.cache.CacheProperties; | ||
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; | ||
import org.springframework.boot.autoconfigure.data.redis.RedisProperties; | ||
import org.springframework.boot.context.properties.EnableConfigurationProperties; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.context.annotation.Primary; | ||
import org.springframework.data.redis.connection.RedisConnectionFactory; | ||
import org.springframework.data.redis.connection.RedisStandaloneConfiguration; | ||
import org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory; | ||
import org.springframework.data.redis.connection.lettuce.LettucePoolingClientConfiguration; | ||
import org.springframework.data.redis.core.RedisTemplate; | ||
|
||
import io.lettuce.core.ClientOptions; | ||
import io.lettuce.core.resource.ClientResources; | ||
import io.lettuce.core.resource.DefaultClientResources; | ||
|
||
@Configuration | ||
@EnableConfigurationProperties(RedisProperties.class) | ||
public class RedisConfig { | ||
@Bean | ||
public Config conf(){ | ||
Config config = new Config(); | ||
Config.RedisConfig conf = new Config.RedisConfig(); | ||
conf.setUri("redis://localhost:6379"); | ||
config.setRedis(conf); | ||
return config; | ||
} | ||
|
||
@Bean | ||
public ClientManager abstractRedisClient(){ | ||
return new ClientManager(); | ||
} | ||
|
||
// @Bean | ||
// public StatefulRedisConnection<String,String> redisClient() { | ||
// return RedisClient.create("redis://localhost:6379").connect(); | ||
// } | ||
|
||
@Bean | ||
public StatefulRedisModulesConnection<String, String> modClient(){ | ||
return RedisModulesClient.create("redis://localhost:6379").connect(); | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
tools/redis-smart-cache-cli/src/main/java/com/redis/smartcache/cli/RedisService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package com.redis.smartcache.cli; | ||
|
||
import com.redis.smartcache.cli.structures.QueryInfo; | ||
|
||
import java.util.List; | ||
|
||
public interface RedisService { | ||
String ping(); | ||
List<QueryInfo> getQueries(String applicationName); | ||
|
||
} |
82 changes: 82 additions & 0 deletions
82
tools/redis-smart-cache-cli/src/main/java/com/redis/smartcache/cli/RedisServiceImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
package com.redis.smartcache.cli; | ||
|
||
import com.fasterxml.jackson.annotation.JsonInclude; | ||
import com.fasterxml.jackson.databind.DeserializationFeature; | ||
import com.fasterxml.jackson.databind.PropertyNamingStrategies; | ||
import com.fasterxml.jackson.dataformat.javaprop.JavaPropsMapper; | ||
import com.redis.lettucemod.api.StatefulRedisModulesConnection; | ||
import com.redis.lettucemod.api.sync.RediSearchCommands; | ||
import com.redis.lettucemod.api.sync.RedisTimeSeriesCommands; | ||
import com.redis.lettucemod.search.Document; | ||
import com.redis.lettucemod.search.SearchResults; | ||
import com.redis.lettucemod.timeseries.GetResult; | ||
import com.redis.lettucemod.timeseries.Label; | ||
import com.redis.smartcache.cli.structures.QueryInfo; | ||
import com.redis.smartcache.cli.util.Util; | ||
import com.redis.smartcache.core.ClientManager; | ||
import com.redis.smartcache.core.Config; | ||
import com.redis.smartcache.core.Config.RuleConfig; | ||
import com.redis.smartcache.core.Query; | ||
import com.redis.smartcache.core.RulesetManager; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.stereotype.Service; | ||
import io.airlift.units.Duration; | ||
|
||
import java.util.*; | ||
import java.util.concurrent.TimeUnit; | ||
|
||
@Service | ||
public class RedisServiceImpl implements RedisService{ | ||
@Autowired | ||
Config conf; | ||
|
||
@Autowired | ||
ClientManager manager; | ||
|
||
@Autowired | ||
StatefulRedisModulesConnection<String, String> connection; | ||
|
||
|
||
public String ping(){ | ||
return connection.sync().ping(); | ||
} | ||
|
||
public List<RuleConfig> GetRules(){ | ||
RulesetManager rulesetManager = new RulesetManager(manager); | ||
|
||
Config.RulesetConfig ruleSetConfig = rulesetManager.getRuleset(conf); | ||
return ruleSetConfig.getRules(); | ||
} | ||
|
||
static String configKeyName(String applicationName){ | ||
return String.format("%s:config", applicationName); | ||
} | ||
|
||
static String HashKeyName(String applicationName, String id){ | ||
return String.format("%s:query:%s", applicationName, id); | ||
|
||
} | ||
|
||
static String IndexName(String applicationName){ | ||
return String.format("%s-query-idx", applicationName); | ||
} | ||
|
||
public List<QueryInfo> getQueries(String applicationName){ | ||
List<QueryInfo> response = new ArrayList<>(); | ||
List<RuleConfig> rules = GetRules(); | ||
|
||
RediSearchCommands<String, String> searchCommands = connection.sync(); | ||
|
||
SearchResults<String, String> searchResults = searchCommands.ftSearch(IndexName(applicationName), "*"); | ||
|
||
for(Document<String, String> doc : searchResults){ | ||
|
||
QueryInfo qi = QueryInfo.fromDocument(doc); | ||
Optional<RuleConfig> currentRule = QueryInfo.matchRule(qi.getQuery(), rules); | ||
currentRule.ifPresent(qi::setCurrentRule); | ||
response.add(qi); | ||
|
||
} | ||
return response; | ||
} | ||
} |
44 changes: 44 additions & 0 deletions
44
tools/redis-smart-cache-cli/src/main/java/com/redis/smartcache/cli/commands/Commands.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package com.redis.smartcache.cli.commands; | ||
|
||
import com.redis.smartcache.cli.RedisServiceImpl; | ||
import com.redis.smartcache.cli.components.TableSelector; | ||
import com.redis.smartcache.cli.structures.QueryInfo; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.shell.component.support.SelectorItem; | ||
import org.springframework.shell.standard.AbstractShellComponent; | ||
import org.springframework.shell.standard.ShellComponent; | ||
import org.springframework.shell.standard.ShellMethod; | ||
|
||
import java.util.ArrayList; | ||
import java.util.Arrays; | ||
import java.util.List; | ||
import java.util.Optional; | ||
|
||
@ShellComponent | ||
public class Commands extends AbstractShellComponent { | ||
@Autowired | ||
RedisServiceImpl client; | ||
|
||
@ShellMethod(key = "ping", value = "ping") | ||
String ping(){ | ||
return client.ping(); | ||
} | ||
|
||
@ShellMethod(key = "list-queries", value = "Get the table of queries", group = "Components") | ||
public String queryTable(){ | ||
List<SelectorItem<QueryInfo>> queries = new ArrayList<>(); | ||
|
||
for (QueryInfo q : client.getQueries("smartcache")){ | ||
queries.add(SelectorItem.of(q.getQueryId(),q)); | ||
} | ||
|
||
TableSelector<QueryInfo, SelectorItem<QueryInfo>> component = new TableSelector<>(getTerminal(), | ||
queries, "queries", null, QueryInfo.getHeaderRow((getTerminal().getWidth()-10)/8)); | ||
component.setResourceLoader(getResourceLoader()); | ||
component.setTemplateExecutor(getTemplateExecutor()); | ||
TableSelector.SingleItemSelectorContext<QueryInfo, SelectorItem<QueryInfo>> context = component | ||
.run(TableSelector.SingleItemSelectorContext.empty()); | ||
QueryInfo result = context.getResultItem().flatMap(si -> Optional.ofNullable(si.getItem())).get(); | ||
return "Got value " + result.toString(); | ||
} | ||
} |
Oops, something went wrong.