New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More →
Socket
Sign inDemoInstall
Socket

cron-redis

Package Overview
Dependencies
Maintainers
1
Versions
16
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

cron-redis - npm Package Compare versions

Comparing version 1.0.2 to 1.1.0

test/t.js

52

api/BullClient.js

@@ -8,7 +8,10 @@ /**

const logger = require('winston');
const redis = require('redis');
const bluebird = require('bluebird');
var methods = {};
var parser = require('cron-parser');
var keysPrefix = 'bull:';
var queue;
var queue, redisClient;
/**

@@ -43,2 +46,4 @@ * 栚捎å‡Ŋ数名æŸĨ扞å‡Ŋ数厞įŽ°

queue = Queue(app, {redis: redisConfig});
redisClient = redis.createClient(redisConfig);
redisClient.select(redisConfig.DB);
queue.on('ready', function () {

@@ -120,13 +125,35 @@ logger.info('%s is ready', app);

//function list(){
// var result = [];
// return client1.getAsync(keysPrefix + 'id').then((ids) => {
// return bluebird.map(ids, function (id) {
// return client1.hgetallAsync(id).then((data) => {
// result.push(data);
// });
// })
// });
//}
function list(){
queue.clean(1000);
var result = [];
return redisClient.keysAsync(keysPrefix + '*').then((ids) => {
return bluebird.map(ids, function (id) {
var key = id.split(':');
if (id && key.length === 3 && parseInt(key[2]) > 0) {
return redisClient.hgetallAsync(id).then((data) => {
data.key = id;
result.push(data);
return data;
});
}
})
}).then(() => {
return result;
}).catch(function(err){
console.error(err);
});
}
/**
* 删除 hash
* @param key
* @returns {*}
*/
function del(key){
return redisClient.delAsync(key).then((data) => {
queue.clean(1000);
return data;
});
}
module.exports = function(app, redisConfig){

@@ -137,4 +164,5 @@ init(app, redisConfig);

register: register,
//list: list
list: list,
del: del
};
}

@@ -8,2 +8,3 @@ /**

DB: 1,
auth_pass: 'root',
opts: {

@@ -10,0 +11,0 @@ auth_pass: 'root',

{
"name": "cron-redis",
"version": "1.0.2",
"version": "1.1.0",
"description": "cron task for node by redis",

@@ -5,0 +5,0 @@ "main": "app.js",

@@ -14,17 +14,25 @@ ## cron task for node by redis

```
var cronRedis = require('cron-redis')(appName, redisConfig);
var redisConfig = require('../config/redis');
const queue = require('../api/BullClient')('test', redisConfig);
var moment = require('moment');
function hello (x, y){
return x + y;
console.log(new Date());
console.log(x + ' + '+ y +' = %s', x+y);
}
cronRedis.register(hello);
var task = {
var task1 = {
method: hello.name,
params: [2, 3],
rule: new Date()
};
rule: moment().add(3, 's').toDate()
}
// publish a task
cronService.publish(task);
var task2 = {
method: hello.name,
params: [4, 5],
rule: '* */1 * * * *'
}
queue.register(hello)
queue.publish(task1);
queue.publish(task2);

@@ -67,2 +75,3 @@

* rule {options} cron rule . {Date} or {* */1 * * * *}
* desc {options} description for task

@@ -90,3 +99,28 @@

#### list
the queue task in redis
* @return {Array[Object]}
```
[{ data: '{"method":"hello","params":[4,5],"rule":"* */1 * * * *"}',
opts: '{"delay":60000}',
progress: '0',
delay: '0',
timestamp: '1458008690942',
attempts: '1',
attemptsMade: '1',
stacktrace: '[]',
returnvalue: 'undefined',
key: 'bull:test:111' },
]
```
### del
delete some hash key
* @param key {string} key of task
### More
[bull](https://github.com/OptimalBits/bull)

@@ -10,3 +10,2 @@ /**

function hello (x, y){
console.log(new Date());
console.log(x + ' + '+ y +' = %s', x+y);

@@ -27,2 +26,6 @@ }

queue.publish(task1);
queue.publish(task2);
//queue.publish(task2);
//queue.del('bull:test:139');
queue.list().then((data) => {
console.log(data);
});
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡ī¸ by Socket Inc