Comments (3)
What's the use case? You should be able to use JavaScript's -Infinty
and Infinty
keywords. They have number
type in typescript.
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 "-inf"
/"+inf"
:
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"]);
});
from handy-redis.
Function parameter that has type: number | "+inf" | "-inf"
, doesn't allow any string. It either has to be string literal "+inf" / "-inf" or variable of type "+inf" | "-inf"
. Passing variable of type string results in:
Argument of type 'string' is not assignable to parameter of type 'number | "+inf" | "-inf"'.ts(2345)
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 number | "+inf" | "-inf"
doesn't have any downsides, and it feels more api compliant.
Anyway, it's still probably low priority.
from handy-redis.
That's a good point, if redis and javascript used different float implementations using Infinty
might not work anymore. Right now the types are automatically generated from redis-doc's command.json (otherwise this project would be very hard to maintain). But the redis-doc just lists max
and min
as double
.
So possibly this issue should be moved to that repo - since it's not actually a double. It's a double, or -inf
, or +inf
, or in fact open ranges like (123
. That last one will be very hard to model in a non-hacky way in typescript, without resorting to string
. Most double
values in commands.json don't allow those special values because they're not limits. I can't off the top of my head think of a clean way to separate min
/max
from, say, the increment amount in incrbyfloat
. Open to suggestions though.
from handy-redis.
Related Issues (20)
- How to add command ? HOT 2
- missing end function HOT 1
- Support redis-mock HOT 2
- How to use SCRIPT LOAD? HOT 2
- Catching the error on connection fail is difficult HOT 1
- Dependency Dashboard
- SPOP return was string[] in 1.x, now it is string, but it can return an Array HOT 3
- Multi Type definition issue HOT 2
- .lpos is not a function HOT 2
- Overloaded multi commands have incorrect type HOT 3
- wrong direction in npm page HOT 4
- Action Required: Fix Renovate Configuration
- Multi commands pass an array to the underlying redis function HOT 2
- TypeError: net.isIP is not a function HOT 1
- "XXXX can't be processed. The connection is already closed." HOT 1
- Scan has `unknown` return type
- zrevrangebyscore functions return unknown[] where zrangebyscore functions return string[]
- Cannot redeclare block-scoped variable 'addCommand' HOT 5
- GEOSEARCH support
- ERR syntax error when using SET
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from handy-redis.