@condor-labs/redis

This module provide and usefull helper to use the official Node_redis library.

Usage no npm install needed!

<script type="module">
  import condorLabsRedis from 'https://cdn.skypack.dev/@condor-labs/redis';
</script>

README

This module provide and usefull helper to use the official Node_redis library.

See official documentation here.

Compatibility

The minimum supported version of Node.js is v8.

How to use it

To use the library you just need to follow the following steps Install the library with npm

npm install @condor-labs/redis

Import the library:

const redis = require('@condor-labs/redis')(settings);

settings object properties

Property Default Description
prefix (String) null A string used to prefix all used keys (e.g. namespace:test). Please be aware that the keys command will not be prefixed. The keyscommand has a "pattern" as argument and no key and it would be impossible to determine the existing keys in Redis if this would be prefixed.
host*(String)* 127.0.0.1 IP address of the Redis server
port (Number) 6379 Port of the Redis server
password (String) null If set, client will run Redis auth command on connect.

Examples

constants.js

module.exports = {
    settings: {
        prefix: 'MY_PREFIX',
        host: 'redis-99999.c11.us-xxx-##.redis.com',
        port: 1234,
        password: '****'
    },
    keyName: 'test:condorlabs-npm-helpers:counter'
};

index.js

const {
    settings,
    keyName
} = require('./constants');

try {
    const redis = require('@condor-labs/redis')(settings);
    (async () => {
        // get client
        let client = await redis.getClient();
        // prepare and execute batch in redis
        const redisBatch = client.batch();
        await redisBatch.incr(keyName);
        await redisBatch.expire(keyName, 1);
        const resolve = await redisBatch.execAsync();
        // validate response
        console.log((resolve && resolve.length > 0 && resolve[0] > 0) ? `REDIS Client connected OK!!!` : `REDIS Client connection failed :(`);
        // close app
        process.exit(1);
    })();
} catch (error) {
    console.error(error)
}

How to Publish

Increasing package version

You will need to update the package.json file placed in the root folder.

identify the property version and increase the right number in plus one.

Login in NPM by console.

 npm login
 [Enter username]
 [Enter password]
 [Enter email]

If all is ok the console will show you something like this : Logged in as USERNAME on https://registry.npmjs.org/.

Uploading a new version

 npm publish --access public

Ref: https://docs.npmjs.com/getting-started/publishing-npm-packages

Note: you will need to have a NPM account, if you don't have one create one here: https://www.npmjs.com/signup

Contributors

The original author and current lead maintainer of this module is the @condor-labs development team.

More about Condorlabs Here.

License

MIT