2
votes

There is a command in Redis - SCAN. It has an option TYPE which return objects that match a given type. When I try to run the set of commands which is provided in the example https://redis.io/commands/scan#the-type-option I get an error ERR syntax error when I run the last command SCAN 0 TYPE zset.

I have prepared objects with the list and zset types, but neither of them works, I always get an exception. Even if I add something on my own, it does not work.

My question is next. Does SCAN actually support TYPE option? I found this issue https://github.com/antirez/redis/issues/3323, but it's not closed and on Redis docs there are such details

Redis version:

redis> INFO
# Server
redis_version:5.0.5
redis> RPUSH list_object "list_element"
redis> TYPE list_object
list
redis> ZADD zset_object 1 "zset_element"
redis> TYPE zset_object
zset
redis> SCAN 0 TYPE zset
ERR syntax error
redis> SCAN 0 type list
ERR syntax error
1

1 Answers

2
votes

The code for TYPE option is still in the unstable branch, and haven't been release to the latest version of Redis. So far, you cannot use that command. You have to wait for the new release to support this feature, or take the risk to use the unstable branch.

However, you can also achieve this goal on the client side:

  1. Use the SCAN command to iterate the key space
  2. For each key, call the type command to do the filter on the client side.

In order to make this operation faster, you can wrap the logic into a Lua script.