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

scan-hget

v0.2.4

Published

Containerized utility to scan Redis keys and hget a specified hashes field.

Downloads

1

Readme

scan-hget

Containerized utility to scan Redis keys and hget a specified hashes field.

See lib/index.js that we use archetype https://github.com/evanx/redis-app

Use case

Sample data

redis-cli hset mytest:1001:h err some_error
redis-cli hset mytest:1002:h err other_error

where we might have the field err on some hashes keys.

We wish to perform a query on this specific field e.g. as follows using bash and redis-cli

for key in `redis-cli keys 'mytest:*:h'`
do
  echo $key `redis-cli hget $key err`
done
mytest:1001:h some_error
mytest:1002:h other_error

Usage

Use format=both to print the key and the field value:

pattern='mytest*' format=both field=err npm start

where we have specified the err field for the query.

mytest:1002:h other_error
mytest:1001:h some_error

where the hash key and the value of its err field have been printed.

Otherwise format=value will print only the field value:

pattern='mytest*' format=value field=err npm start
other_error
some_error

Config

See lib/spec.js

    pattern: {
        description: 'the matching pattern for Redis scan',
        example: '*'
    },
    field: {
        description: 'name of the hashes field to print'
    },
    limit: {
        description: 'the maximum number of keys to print',
        note: 'zero means unlimited',
        default: 30
    },
    format: {
        description: 'the output format',
        options: ['key', 'value', 'both', 'json'],
        default: 'key'
    }

Implementation

See lib/main.js

    let cursor;
    while (true) {
        const [result] = await multiExecAsync(client, multi => {
            multi.scan(cursor || 0, 'match', config.pattern);
        });
        cursor = parseInt(result[0]);
        const keys = result[1];
        if (config.format === 'key') {
            keys.forEach(key => {
                console.log(key);
                count++;
            });
        }
    }

Docker

Having audited the Dockerfile and code, you can build and run as follows:

docker build -t scan-hget https://github.com/evanx/scan-hget.git

where we tag the image as scan-hget

docker run --network=host -e pattern='*' -e field=role -e format=both scan-hget

where --network-host connects the container to your localhost bridge. The default redisHost of localhost works in that case.

https://twitter.com/@evanxsummers