npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

redimension

v1.0.0

Published

Redis multi-dimensional query library

Downloads

6

Readme

Redimension

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.

Usage

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.

Unindexing

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.

Tests

npm test

License

The code is released under the BSD 2 clause license.