Search code examples
javaredisjedisspring-data-rediskey-value-store

ERR syntax error while performing SCAN operations in Redis using Spring Data Redis


While working with Redis using Spring Data Redis, I tried to scan hash data in my server (similar to HSCAN in CLI) -

Cursor<Entry<Object,Object>> scan = redisTemplate.opsForHash().scan("student", new ScanOptionsBuilder().count(0).match("*").build());

While running this I get the below error -

redis.clients.jedis.exceptions.JedisDataException: ERR syntax error

Can anyone help me how to solvw this.

There are many related discussions but none of them provide clear answer.


Solution

  • You should use count > 0, or not using count at all (default is 10).

    From looking at ScanOptions.java, if count is used, it is passed to the command without any checks.

    A quick check on redis-cli shows COUNT 0 throws ERR syntax error.

    > hset hash1 f v
    (integer) 1
    > hscan hash1 0 MATCH * COUNT 0
    (error) ERR syntax error
    > hscan hash1 0 MATCH * COUNT 1
    1) "0"
    2) 1) "f"
       2) "v"
    

    See SCAN > The COUNT option for more details. It doesn't state it has to be greater than 0 though but makes sense it should.