Giter VIP home page Giter VIP logo

queue's Introduction

DistributedQueue

Ascent24

A simple distributed queue data structure for Node.js. Backed by Redis.

100% Fully covered in Mocha Unit Tests.

Pull requests are well come.

Heavily inspired by priorityqueuejs https://github.com/janogonzalez/priorityqueuejs

Installation

npm install distributedqueue

Example

  let storage = new RedisStorage();
  let queuename = "<NameoftheQueue>"

  //same as ioredis connection object. 
  redisConnObj = {  
     host: "localhost",
     port: 6379,
  }
  var queue = new DistributedQueue(queuename, storage, redisConnObj);
  await queue.initializeStorage();
  await queue.flush();//Becareful on this. will flush all items in the queue
  await queue.enq('jano');
  await queue.enq('valentina');
  await queue.peek()
  await queue.isEmpty() 

API

DistributedQueue()

Initializes a new empty DistributedQueue object

object.initializeStorage();

Initializes a new empty DistributedQueue in redis OR connect to already existing queue created by other servers.

object.deq()

Dequeues the top element of the distributed queue. Throws an Error when the queue is empty.

object.enq(element)

Enqueues the element at the distributed queue and returns its new size.

object.flush()

Flushes all the items in the current queue. Does not alter/remove metadata about this queue. Just be careful this will delete all items in the queue in redis as well.

object.isEmpty()

Returns whether the distributed queue is empty or not.

object.peek()

Peeks at the top element of the distributed queue. Throws an Error when the queue is empty.

object.size()

Returns the size of the distributed queue.

Testing

npm install
npm test

  DistributedQueue()
    √ returns an new DistributedQueue
    #isEmpty()
      √ returns true when the queue is empty
      √ returns false when the queue is not empty
    #peek()
      √ fails when the queue is empty
      √ returns the top element of the queue
    #deq()
      √ fails when the queue is empty
      √ dequeues the top element of the queue
      √ not fails with only one element
    #enq()
      √ enqueues an element at the end of the queue
      √ returns the new size of the queue
    #size()
      √ returns 0 when the queue is empty
      √ returns the size of the queue

  51 passing (16s)

Stay in touch

About Ascent24 Technologies

  • Ascent24 Technologies, An Innovative digital products developer & service provider for Startups & well-established software companies. We are specialised in developing high performance Software Applications, Specifically expert in Travel, Airline, Hotel Industry.

Licence

MIT

queue's People

Contributors

thiyaga24 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.