-
Notifications
You must be signed in to change notification settings - Fork 23.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
SCAN: New Feature SCAN cursor [TYPE type]
modifier suggested in issue #6107
#6116
Conversation
…#6107. Add tests to check basic functionality of this optional keyword, and also tested with a module (redisgraph). Checked quickly with valgrind, no issues. Copies name the type name canonicalisation code from `typeCommand`, perhaps this would be better factored out to prevent the two diverging and both needing to be edited to add new `OBJ_*` types, but this is a little fiddly with C strings. The [redis-doc](https://github.com/antirez/redis-doc/blob/master/commands.json) repo will need to be updated with this new arg if accepted. A quirk to be aware of here is that the GEO commands are backed by zsets not their own type, so they're not distinguishable from other zsets. Additionally, for sparse types this has the same behaviour as `MATCH` in that it may return many empty results before giving something, even for large `COUNT`s.
Looks good, although I'm not sure about the two "new" types introduced: 'none' and 'unknown'. |
@itamarhaber Yeah, there's a little difficulty in working out how to handle those errors here - These values are possible but not actually types so we maybe ought to do and return nothing...
|
…n SCAN and TYPE commands, and to keep OBJ_* enum to string canonicalization in one place.
@antirez any opinion on whether this would be a useful feature to have? |
Hello @AngusP, this feature looks good to me, thanks a lot for proposing. Please could you operate the following trivial changes?
Thanks! |
@antirez will do, apologies - should’ve spotted the style! |
@AngusP I apologize for asking about the changes actually, it's not the important part of the PR, but given that it's a trivial change, better to stay consistent :-) Thanks. |
@antirez see new commit for your recommended changes |
Thanks @AngusP, merged! If you will follow up with redis-doc as well, it will be appreciated. Make sure to comment here as well once you submit the doc PR as the redis-doc repo is inspected with a different frequency. Thank you. |
P.S. In the unit tests you wrote, I would change them to include a non-string object in the first iteration, because to test all-white all-black is generally not able to visit as many states as testing for mixed conditions. |
@antirez redis-doc redis/redis-doc#1137 I'm not too sure what you mean "I would change them to include a non-string object in the first iteration", do you mean to test for a database populated with a mix of strings and not-strings? I'd agree that would be a more robust test, but there's no easy |
@antirez can it be ported to 5.0.x too? |
@AngusP Hey! I just mean: DEBUG POPULATE ... + ZADD foobar, so you have at least a key that is not a string. And later you check that the count is 1000 and 1 :-D Thanks for the doc. |
SCAN: New Feature `SCAN cursor [TYPE type]` modifier suggested in issue redis#6107
NOTE: [This comment](redis/redis#6116 (comment)) indicates the feature may be backported to Redis 5, so we'll want to change our unit test if that happens.
NOTE: [This comment](redis/redis#6116 (comment)) indicates the feature may be backported to Redis 5, so we'll want to change our unit test if that happens.
Extends the
SCAN
(but notZSCAN
,HSCAN
etc.) API toThis allows scanning the DB for keys of a single type, which may be useful for finding streams, garbage collection, migrations etc.
The feature was suggested by @gkorland in #6107.
The argument
type
is the string you get when asking Redis for theTYPE
of a key, so works with modules as well as the native types. A quirk to be aware of here is that the GEO commands are backed by ZSETs not their own type, so they're not distinguishable from other ZSETs. Similarly, Hyperloglogs, bitmaps and bit fields are backed by strings so are also not distinguishable.Additionally, for sparse types that are rare in the DB, this has the same behaviour as
MATCH
in that it may return many empty results before giving something, even for largeCOUNTs
.Also adds tests to check basic functionality of this optional
TYPE
keyword, and also tested with a module (redisgraph). Checked quickly with valgrind, no issues.Copies name the type name canonicalisation code from
typeCommand
, perhaps this would be better factored out to prevent the two diverging and both needing to be edited to add newOBJ_*
types, but this is a little fiddly/messy with C string, so I haven't addressed it.The redis-doc repo will need to be updated with this new arg if accepted.
Many thanks as always 👍