
Security News
Package Maintainers Call for Improvements to GitHub’s New npm Security Plan
Maintainers back GitHub’s npm security overhaul but raise concerns about CI/CD workflows, enterprise support, and token management.
redimension
Advanced tools
Based on https://github.com/antirez/redimension
Redimension is a Redis multi-dimensional indexing and querying library implemented in order to index items in N-dimensions, and then asking for elements where each dimension is within the specified ranges.
Currently the library can index only unsigned integers of the specified precision. There are no precision limits, you can index integers composed of as much bits as you like: you specify the number of bits for each dimension in the constructor when creating a Redimension object.
An example usage in 2D is the following. Imagine you want to index persons by salary and age:
myindex = new Redimension(redis_client, "people-by-salary", 2, 64)
We created a Redimension object specifying a Redis object that must respond to the Redis commands. We specified we want 2D indexing, and 64 bits of precision for each dimension. The first argument is the key name that will represent the index as a sorted set.
Now we can add elements to our index.
myindex.index([45,120000], "Josh")
myindex.index([50,110000], "Pamela")
myindex.index([30,125000], "Angela")
The index
method takes an array of integers representing the value of each
dimension for the item, and an item name that will be returned when asking
for ranges during the query stage.
Querying is simple. In the following query we ask for all the people with age between 40 and 50, and salary between 100000 and 115000.
myindex.query([[40,50],[100000,115000]]).then(results => {
console.log(results) // [50, 110000, "Pamela"]
});
Ranges are always inclusive. Not a big problem since currently we can only index integers so just increment/decrement to exclude a given value.
If you want to play with the library, the above example is shipped with
the source code, the file is called example1.js
.
There are two ways in order to remove indexed data from the index. One
is to specify again the coordinates and the ID, using the unindex
method:
myindex.unindex([45,120000],"Josh")
However sometimes it is no longer possible to have the old data, we want just unindex or update our coordinates for a given element. In this case we may enable a feature of the library called Hash mapping. We enable it by setting a key which will represent, using an Hash type, a map between the item ID and the current indexed representation:
myindex.hashkey = "people-by-salary-map"
Once this is enabled, each time we use the index
method, an hash entry
will be created at the same time. We can now use two additional methods.
One will simply remove an item from the index just by ID:
myindex.unindex_by_id("Josh")
The other is a variant of index
that removes and re-adds the element with
the updated coordinates:
myindex.update([46,120000],"Josh")
It is imporatnt to enable this feature after the object is created, and
consistently for all the queries, so that the Hash and the sorted set
are in sync. When this feature is enabled, to use index
is not a good
idea and update
should be used instead regardless the added element
areadly exists or not inside the index. Please refer to example2.js
for
an example.
npm test
The code is released under the BSD 2 clause license.
FAQs
Redis multi-dimensional query library
We found that redimension demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Maintainers back GitHub’s npm security overhaul but raise concerns about CI/CD workflows, enterprise support, and token management.
Product
Socket Firewall is a free tool that blocks malicious packages at install time, giving developers proactive protection against rising supply chain attacks.
Research
Socket uncovers malicious Rust crates impersonating fast_log to steal Solana and Ethereum wallet keys from source code.