-
Notifications
You must be signed in to change notification settings - Fork 10
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 doesn't allow +inf/-inf #30
Comments
What's the use case? You should be able to use JavaScript's Using strings for number-typed arguments is exactly the sort of thing this library is supposed to protect against, unless you've found something you're unable to do. This works, and IMO is better than using it("can use zrangebyscore with infinite limits", async () => {
const client = createHandyClient();
await client.zadd("myzset", [1, "one"], [2, "two"], [3, "three"], [-Number.MAX_VALUE, "lowest"], [Number.MAX_VALUE, "highest"]);
const all = await client.zrangebyscore("myzset", -Infinity, Infinity);
expect(all).toEqual(["lowest", "one", "two", "three", "highest"]);
const positives = await client.zrangebyscore("myzset", 0, Infinity);
expect(positives).toEqual(["one", "two", "three", "highest"]);
const negatives = await client.zrangebyscore("myzset", -Infinity, 0);
expect(negatives).toEqual(["lowest"]);
}); |
Function parameter that has type:
Although passing Infinity has the same result (thanks to the fact that node uses the same 64 bit floating point numbers as redis), it doesn't mean it has the same effect under the hood. I can imagine that passing "+inf" could be slightly faster, as it always means 'last element in set' and this search could be done in O(1), where as search for any number (including infinity) takes O(log n). I could be wrong about the fact that there is any noticeable difference, but having type Anyway, it's still probably low priority. |
That's a good point, if redis and javascript used different float implementations using So possibly this issue should be moved to that repo - since it's not actually a double. It's a double, or |
…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.
Type definitions of some redis commands are not complete. For example here is type definition for
zrangebyscore(key: string, min: number, max: number, withscores: "WITHSCORES", offset_count: ["LIMIT", number, number]): Promise<any[]>;
Min
andmax
arguments accept only number, where node_redis could also accept string or just "+inf" | "-inf".The text was updated successfully, but these errors were encountered: