I have a requirement that I needs to search in Redis Cache based on 3 hashKey fields - (clientId - String, securityId - String and transactionDate - Date). I did a basic POC where I implement a simple enough method to find by Id.
Code:
private RedisTemplate<String, EquityFeeds> redisTemplate;
private HashOperations hashOperations;
public EquityFeedsRedisRepositoryImpl(RedisTemplate<String, EquityFeeds> redisTemplate) {
this.redisTemplate = redisTemplate;
this.hashOperations = redisTemplate.opsForHash();
}
public EquityFeeds findById(String id) {
return (EquityFeeds) hashOperations.get("KEY", id);
}
Now how do I search in RedisCache based on the above 3 hashKeys - (clientId - String, securityId - String and transactionDate - Date).
I have a very basic and simple save operation:
Code:
@Override
public void save(EquityFeeds equityFeeds) {
hashOperations.put("EQUITY", equityFeeds.getId(), equityFeeds);
}
I found only one article of relevance on RediSearch for Java - JRediSearch - RediSearch Java Client https://oss.redislabs.com/redisearch/java_client.html
When I ran a program sample using this site: Code:
public static void main(String[] args) {
Client client = new Client("EQUITY", "localhost",6379);
Schema sc = new Schema()
.addTagField("clientId")
.addTagField("securityId")
.addTagField("transactionDate");
client.createIndex(sc, Client.IndexOptions.defaultOptions());
Map<String, Object> fields = new HashMap<String, Object>();
fields.put("clientId", "hello world");
fields.put("securityId", "lorem ipsum");
fields.put("transactionDate", "1337");
client.addDocument("doc1", fields);
Query q = new Query("hello world");
SearchResult res = client.search(q);
System.out.println("Result: "+res.totalResults);
}
I am getting an exception as below:
Exception in thread "main" redis.clients.jedis.exceptions.JedisDataException: ERR unknown command 'FT.CREATE'
in the line
client.createIndex(sc, Client.IndexOptions.defaultOptions());
I am not getting any resolution for this on the net.