{"id":22338035,"url":"https://github.com/sunkuo/redis-message-queue","last_synced_at":"2025-07-29T22:33:15.287Z","repository":{"id":57349775,"uuid":"56493647","full_name":"sunkuo/redis-message-queue","owner":"sunkuo","description":null,"archived":false,"fork":false,"pushed_at":"2016-05-04T06:11:09.000Z","size":18,"stargazers_count":5,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2024-11-13T11:41:52.549Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/sunkuo.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-04-18T09:12:50.000Z","updated_at":"2018-04-20T07:13:16.000Z","dependencies_parsed_at":"2022-09-15T15:33:32.433Z","dependency_job_id":null,"html_url":"https://github.com/sunkuo/redis-message-queue","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sunkuo%2Fredis-message-queue","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sunkuo%2Fredis-message-queue/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sunkuo%2Fredis-message-queue/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sunkuo%2Fredis-message-queue/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/sunkuo","download_url":"https://codeload.github.com/sunkuo/redis-message-queue/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":228054438,"owners_count":17862129,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-12-04T06:12:52.257Z","updated_at":"2024-12-04T06:12:52.789Z","avatar_url":"https://github.com/sunkuo.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Redis as Queue - Node.js SDK\n\nNote: This is A node.js package for regarding redis as a message queue, npm repo: https://www.npmjs.com/package/redis-message-queue\n\n\n## Installation\n\n```shell\n$ npm install redis-message-queue\n```\n\n## Usage\n\nThere are two kinds of queue - normal queue and unique queue.\n\nEach value in unique queue is unique. If a new value that equals any value in the queue, you may choose to update or not.\n\nFirst you should require this package:\n\n```javascript\nvar rmq = require(\"redis-message-queue\");\n```\n\n### Normal Queue\n\n#### Create\n\n```javascript\nvar normalQueue = new rmq.NormalQueue(QUEUE_NAME, [...]);\n```\n\n\u003e **Note:** `[...]` is the option(s) to connect redis server. Refer to [node-redis document](https://www.npmjs.org/package/redis#redis-createclient-).\n\u003e\n\u003e Eg.\n\u003e\n\u003e ```javascript\n\u003e new rmq.NormalQueue(QUEUE_NAME, 6379, '127.0.0.1', {});\n\u003e new rmq.NormalQueue(QUEUE_NAME, unix_socket, options);\n\u003e ...\n\u003e ```\n\n#### Select\n\nTo Select a db :\n\n```javascript\nnormalQueue.select(db, function() {\n    console.log(\"db select success\");\n});\n```\n\n\n#### Push\n\nTo push a message to your queue, you may use this function:\n\n```javascript\nnormalQueue.push(\"YOUR MESSAGE\", function(err) {\n    console.log(err);\n});\n```\n\n#### Get\n\nTo get message(s) from your redis queue, you may use `get` function.\n\n##### Get earlist one message\n\n```javascript\nnormalQueue.get(function(err, messages) {\n    console.log(err);\n    if(messages.length) console.log(messages[0]);\n});\n```\n\n##### Get earlist N message(s)\n\n```javascript\n// This call gets 10 earlist messages\nnormalQueue.get(10, function(err, messages) {\n    console.log(err);\n    for(var i = 0; i \u003c messages.length; i++) console.log(messages[i]);\n});\n```\n\n##### Get all message(s)\n\n```javascript\nnormalQueue.get(-1, function(err, messages) {\n    console.log(err);\n    for(var i = 0; i \u003c messages.length; i++) console.log(messages[i]);\n});\n```\n\n#### Remove\n\nTo remove message(s) from your redis queue, you may use `removeAmount` function.\n\n##### Remove earlist one message\n\n```javascript\nnormalQueue.removeAmount(function(err) {\n    console.log(err);\n});\n```\n\n##### Remove earlist N message(s)\n\n```javascript\nnormalQueue.removeAmount(5, function(err) {\n    console.log(err);\n});\n```\n\n##### Remove all the message(s)\n\n```javascript\nnormalQueue.removeAmount(-1, function(err) {\n    console.log(err);\n});\n```\n\n#### Length\n\nGet the length of current queue.\n\n```javascript\nnormalQueue.length(function(err, len) {\n    console.log(len);\n});\n```\n\n### Unique Queue\n\nEach message in unique queue is unique.\n\n#### Create\n\n```javascript\nvar uniqueQueue = new rmq.UniqueQueue(QUEUE_NAME, [...]);\n```\n\n\u003e **Note:** `[...]` is the option(s) to connect redis server. Refer to [node-redis document](https://www.npmjs.org/package/redis#redis-createclient-).\n\u003e\n\u003e Eg.\n\u003e\n\u003e ```javascript\n\u003e new rmq.UniqueQueue(QUEUE_NAME, 6379, '127.0.0.1', {});\n\u003e new rmq.UniqueQueue(QUEUE_NAME, unix_socket, options);\n\u003e ...\n\u003e ```\n\n\n#### Select\n\nTo Select a db :\n\n```javascript\nnormalQueue.select(db, function() {\n    console.log(\"db select success\");\n});\n```\n\n#### Push\n\nPush a message to the queue.\n\n##### Need update\n\nThis call will check if your message is existing. If existing, it will move the previous message to the end of queue. Otherwise, your message will be pushed at the end of queue.\n\n```javascript\nuniqueQueue.push(\"YOUR_MESSAGE\", true, function(err) {\n    console.log(err);\n});\n```\n\n##### Do not update\n\nThis call will check if your message is existing. If existing, it won't do anything. Otherwise, your message will be pushed at the end of queue.\n\n```javascript\nuniqueQueue.push(\"YOUR_MESSAGE\", function(err) {\n    console.log(err);\n});\n\n// or you can do this\n\nuniqueQueue.push(\"YOUR_MESSAGE\", false, function(err) {\n    console.log(err);\n});\n```\n\n#### Get\n\n##### Get first message\n\n```javascript\nuniqueQueue.get(function(err, messages) {\n    console.log(err);\n    if(messages.length) {\n        console.log(messages[0].message);\n        console.log(messages[0].updatedAt);\n    }\n});\n```\n\n##### Get first N message(s)\n\n```javascript\nuniqueQueue.get(3, function(err, messages) {\n    console.log(err);\n    for(var i = 0; i \u003c messages.length; i++) {\n        console.log(messages[i].message);\n        console.log(messages[i].updatedAt);\n    }\n});\n```\n\n##### Get all the message(s)\n\n```javascript\nuniqueQueue.get(-1, function(err, messages) {\n    console.log(err);\n    for(var i = 0; i \u003c messages.length; i++) {\n        console.log(messages[i].message);\n        console.log(messages[i].updatedAt);\n    }\n});\n```\n\n#### Remove Amount\n\nRefer to [remove section](#remove) in **Normal Queue**.\n\n#### Remove Messages\n\nRemove one or more certain message(s) in the queue.\n\n```javascript\nuniqueQueue.get(10, function(err, messages) {\n    for(var i = 0; i \u003c 5; i++) messages.shift();\n\n    // Remove Messages\n    uniqueQueue.removeMessages(messages, function(err, removeCount, notRemovedMessages) {\n        console.log(err);\n        console.log(removeCount);\n        for(var i = 0; i \u003c notRemovedMessages.length; i++) console.log(notRemovedMessages[i].message);\n    });\n});\n```\n\n#### Length\n\nRefer to [length section](#length) in **Normal Queue**.\n\n### Common Functions\n\n#### Delete Queue\n\nDelete this queue key and values in redis.\n\n```javascript\nuniqueQueue.deleteQueue(function() {});\nnormalQueue.deleteQueue(function() {});\n```\n\n#### Destroy Queue Object\n\nLet the queue object disconnect from redis server and let this instance can't do any other thing any more.\n\n```javascript\nuniqueQueue.destroy();\nnormalQueue.destroy();\n```\n\n## Contribute\n\nYou're welcome to pull requests!\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsunkuo%2Fredis-message-queue","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsunkuo%2Fredis-message-queue","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsunkuo%2Fredis-message-queue/lists"}