3

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.

shreyas.k
  • 181
  • 1
  • 2
  • 15

1 Answers1

1

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.

LeoMurillo
  • 6,048
  • 1
  • 19
  • 34
  • When I use **count > 0** or remove count parameter, the returned value by SCAN is - **org.springframework.data.redis.core.ConvertingCursor@555ec143** I want the data to be printed similar to how it is printed on CLI. @LeoMurillo – shreyas.k Jan 02 '20 at 14:09
  • You need to call multiple times, while you capture the keys. See examples at https://www.programcreek.com/java-api-examples/index.php?api=org.springframework.data.redis.core.ScanOptions – LeoMurillo Jan 02 '20 at 14:32