Nutritious Pumpkin Masses

    queuep-redis

    1.2.1 • Public • Published

    queuep-redis

    This is a redis based storage strategy for queuep. Thus to make use of this library you should be using queuep already.

    QueueP is a congestion control framework designed for NodeJs applications. Go have a look at https://www.npmjs.com/package/queuep

    Installation

    npm install --save queuep-redis
    

    Usage

    Note: We assume that you already have a redis-server up and running.

    First import queuep and queuep-redis

    import qp from 'queuep';
    import RedisStore from 'queuep-redis';
    

    Then you can set the storage to queuep-redis when initializing queuep by providing the store as the first argument to init method. Note that we are using uppercase for the first letter since the store imported from queuep-redis is a class definition. It is not compulsory, but makes more sense internally.

    qp.init(RedisStore);
    

    This class is initiated by queuep. If you want to customize the redis connection, then you can pass an optional options object to the init method. The following example shows how you can authenticate the connection, change the database to the index 1 and change the unix socket path.

    qp.init(RedisStore, {
        password: "secret_password",
        path: "unix socket path",
        db: 1
    });
    

    You can also set the storage using the useStore method.

    qp.useStore(RedisStore, options);
    

    We recommend to set the storage before initializing any queuep queues. It would not break the code if not. But the code will look cleaner with the recommended approach.

    You can also set redis storage to a particular queue while initializing a queue. To do that,

    let myQueue = qp.initQueue("my_queue", {
        consumer: this.myConsumer,
        storeSpec: {
            store: RedisStore,
            options: {
                /* 
                 * Redis connection options can be specified here
                 * For instance, if you have enabled authentication in the redis server, you can pass the password here
                 * Or else, if you want to use a different database, you can pass the db index here
                 * For all available options, please refer the node_redis docs at https://www.npmjs.com/package/redis#rediscreateclient
                */
            }
        }
    });
    

    Or even after initializing using the setStore method. But we would not recommend this unless there is no other choice.

    To do that,

    let queue = qp.getQueueInstance("my_queue");
    queue.setStore(RedisStore, options);
    

    or

    qp.setStore("my_queue", RedisStore, options);

    Install

    npm i queuep-redis

    DownloadsWeekly Downloads

    0

    Version

    1.2.1

    License

    MIT

    Unpacked Size

    12.3 kB

    Total Files

    4

    Last publish

    Collaborators

    • pubudud
    • pupudu