Search code examples
springredisspring-data-redis

Filter based on Integer Comparison in Spring data redis


I am using spring-data-redis to communicate with database.

I have entity class like below

@RedisHash(value = "employee")
public class Employee
{
    @Id
    private long id;
    @Indexed
    private String name;
    @Indexed
    private int age;
    private Address address;

    ...... ...... ......

}

I want to filter the employees based on age group. For example, age lesser than 35 (age<35). How to achieve this in below repository?

@Repository
public interface EmployeeRepo extends CrudRepository<Employee, Long>
{
    public Employee findByName(String name);
}

I dont prefer to load complete data from table and do search using any loop/stream.


Solution

  • I don't think it does. I tried to implement what you tried to do using

    @Index
    long lastUpdatedOn;
    

    when I checked the redis it gives a key entity:lastUpdatedOn:160.... and I tried searching for it using ZRANGE which gives no results.