Skip to content
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

ZRANGEBYSCORE min/max argument types not complete #1420

Open
mmkal opened this issue Oct 21, 2020 · 2 comments
Open

ZRANGEBYSCORE min/max argument types not complete #1420

mmkal opened this issue Oct 21, 2020 · 2 comments

Comments

@mmkal
Copy link
Contributor

mmkal commented Oct 21, 2020

In commands.json, ZRANGEBYSCORE has its min and max arguments as double:

redis-doc/commands.json

Lines 3806 to 3813 in e978cf5

{
"name": "min",
"type": "double"
},
{
"name": "max",
"type": "double"
},

But the value is also allowed to be +inf, -inf, (1 etc.

Likewise with ZREMRANGEBYSCORE, ZREVRANGEBYSCORE and ZCOUNT.

It'd be great if commands.json could somehow indicate that more than just double is allowed.

Note that #1232 would solve this problem with no extra effort, because this is already possible to express precisely with json schema:

name: min
schema:
  anyOf:
  - type: number
  - type: string
    enum: [-inf, +inf]
  - type: string
    pattern: ^\(\d+(\.\d+)?$
json equivalent
{
   "name": "min",
   "schema": {
      "anyOf": [
         {
            "type": "number"
         },
         {
            "type": "string",
            "enum": [
               "-inf",
               "+inf"
            ]
         },
         {
            "type": "string",
            "pattern": "^\\(\\d+(\\.\\d+)?$"
         }
      ]
   }
}

Related: mmkal/handy-redis#30

mmkal added a commit to mmkal/handy-redis that referenced this issue Oct 26, 2020
…240)

Fixes #30

Now that v2 has a more maintainable "patching" system, this works around redis/redis-doc#1420 - to be removed if a fix is merged there.

This effectively allows string values to be passed as min and max for ZRANGEBYSCORE, ZREMRANGEBYSCORE, ZREVRANGEBYSCORE and ZCOUNT.

Note: in future, it may be possible to use template literal types to only allow strings like (1 rather than any strings, but it's likely too complex and will require a higher typescript version than most users have.
@ayruslore
Copy link
Contributor

I think the issue is resolved in this pull request (mmkal/handy-redis#240). This issue can be closed

@mmkal
Copy link
Contributor Author

mmkal commented Jan 16, 2021

That's just a workaround in a downstream library. The issue is that commands.json in this repo reports an incomplete type for the min/max arguments, and that's still the case, so it shouldn't be closed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants