Commit 2d663521 by zCaesar

add redis

parent c10d8082
...@@ -105,9 +105,14 @@ module.exports = function (options = {}) { ...@@ -105,9 +105,14 @@ module.exports = function (options = {}) {
// cache missed // cache missed
authCheck(req.body.client_id, req.body.username, req.body.password, function (result) { authCheck(req.body.client_id, req.body.username, req.body.password, function (result) {
cache.set(cachekey, result); cache.set(cachekey, result);
res.send({ require('./redis/on_register').on_register_redis(req.body.client_id).then(status => {
"result": result ? "ok" : "no" console.log('redis:status: ' + status)
}); res.send({
"result": status ? "ok" : "no"
});
})
// const util = require('util')
// console.log(util.inspect(status, false, null, true))
}); });
} }
else { else {
......
module.exports = function(options = {}) { module.exports = function(options = {}) {
return function (req, res, next) { return function (req, res, next) {
doRedis() doRedis(req.body)
} }
function doRedis() { function doRedis(body) {
console.log(body)
} }
} }
\ No newline at end of file
...@@ -83,6 +83,11 @@ ...@@ -83,6 +83,11 @@
"safe-json-stringify": "~1" "safe-json-stringify": "~1"
} }
}, },
"cluster-key-slot": {
"version": "1.0.12",
"resolved": "https://registry.npmjs.org/cluster-key-slot/-/cluster-key-slot-1.0.12.tgz",
"integrity": "sha512-21O0kGmvED5OJ7ZTdqQ5lQQ+sjuez33R+d35jZKLwqUb5mqcPHUsxOSzj61+LHVtxGZd1kShbQM3MjB/gBJkVg=="
},
"commander": { "commander": {
"version": "2.15.1", "version": "2.15.1",
"resolved": "http://registry.npmjs.org/commander/-/commander-2.15.1.tgz", "resolved": "http://registry.npmjs.org/commander/-/commander-2.15.1.tgz",
...@@ -152,6 +157,11 @@ ...@@ -152,6 +157,11 @@
"ms": "2.0.0" "ms": "2.0.0"
} }
}, },
"denque": {
"version": "1.3.0",
"resolved": "https://registry.npmjs.org/denque/-/denque-1.3.0.tgz",
"integrity": "sha512-4SRaSj+PqmrS1soW5/Avd7eJIM2JJIqLLmwhRqIGleZM/8KwZq80njbSS2Iqas+6oARkSkLDHEk4mm78q3JlIg=="
},
"detect-node": { "detect-node": {
"version": "2.0.4", "version": "2.0.4",
"resolved": "https://registry.npmjs.org/detect-node/-/detect-node-2.0.4.tgz", "resolved": "https://registry.npmjs.org/detect-node/-/detect-node-2.0.4.tgz",
...@@ -237,6 +247,11 @@ ...@@ -237,6 +247,11 @@
"semver-store": "^0.3.0" "semver-store": "^0.3.0"
} }
}, },
"flexbuffer": {
"version": "0.0.6",
"resolved": "https://registry.npmjs.org/flexbuffer/-/flexbuffer-0.0.6.tgz",
"integrity": "sha1-A5/fI/iCPkQMOPMnfm/vEXQhWzA="
},
"formidable": { "formidable": {
"version": "1.2.1", "version": "1.2.1",
"resolved": "https://registry.npmjs.org/formidable/-/formidable-1.2.1.tgz", "resolved": "https://registry.npmjs.org/formidable/-/formidable-1.2.1.tgz",
...@@ -350,6 +365,38 @@ ...@@ -350,6 +365,38 @@
"resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.3.tgz", "resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.3.tgz",
"integrity": "sha1-Yzwsg+PaQqUC9SRmAiSA9CCCYd4=" "integrity": "sha1-Yzwsg+PaQqUC9SRmAiSA9CCCYd4="
}, },
"ioredis": {
"version": "4.2.0",
"resolved": "https://registry.npmjs.org/ioredis/-/ioredis-4.2.0.tgz",
"integrity": "sha512-PdxZGNJBfPiR2RI6DkqmiacL1+ML3gaqEiaC5QXWQt9eSTlGj+BwDCct0s8irn1ed8GyzAHTzcjvU9fmnl6D7A==",
"requires": {
"cluster-key-slot": "^1.0.6",
"debug": "^3.1.0",
"denque": "^1.1.0",
"flexbuffer": "0.0.6",
"lodash.defaults": "^4.2.0",
"lodash.flatten": "^4.4.0",
"redis-commands": "1.4.0",
"redis-errors": "^1.2.0",
"redis-parser": "^3.0.0",
"standard-as-callback": "^1.0.0"
},
"dependencies": {
"debug": {
"version": "3.2.6",
"resolved": "https://registry.npmjs.org/debug/-/debug-3.2.6.tgz",
"integrity": "sha512-mel+jf7nrtEl5Pn1Qx46zARXKDpBbvzezse7p7LqINmdoIk8PYP5SySaxEmYv6TZ0JyEKA1hsCId6DIhgITtWQ==",
"requires": {
"ms": "^2.1.1"
}
},
"ms": {
"version": "2.1.1",
"resolved": "https://registry.npmjs.org/ms/-/ms-2.1.1.tgz",
"integrity": "sha512-tgp+dl5cGk28utYktBsrFqA7HKgrhgPsg6Z/EfhWI4gl1Hwq8B/GmY/0oXZ6nF8hDVesS/FpnYaD/kOWhYQvyg=="
}
}
},
"isarray": { "isarray": {
"version": "1.0.0", "version": "1.0.0",
"resolved": "https://registry.npmjs.org/isarray/-/isarray-1.0.0.tgz", "resolved": "https://registry.npmjs.org/isarray/-/isarray-1.0.0.tgz",
...@@ -460,6 +507,16 @@ ...@@ -460,6 +507,16 @@
"resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.10.tgz", "resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.10.tgz",
"integrity": "sha512-UejweD1pDoXu+AD825lWwp4ZGtSwgnpZxb3JDViD7StjQz+Nb/6l093lx4OQ0foGWNRoc19mWy7BzL+UAK2iVg==" "integrity": "sha512-UejweD1pDoXu+AD825lWwp4ZGtSwgnpZxb3JDViD7StjQz+Nb/6l093lx4OQ0foGWNRoc19mWy7BzL+UAK2iVg=="
}, },
"lodash.defaults": {
"version": "4.2.0",
"resolved": "https://registry.npmjs.org/lodash.defaults/-/lodash.defaults-4.2.0.tgz",
"integrity": "sha1-0JF4cW/+pN3p5ft7N/bwgCJ0WAw="
},
"lodash.flatten": {
"version": "4.4.0",
"resolved": "https://registry.npmjs.org/lodash.flatten/-/lodash.flatten-4.4.0.tgz",
"integrity": "sha1-8xwiIlqWMtK7+OSt2+8kCqdlph8="
},
"lodash.get": { "lodash.get": {
"version": "4.4.2", "version": "4.4.2",
"resolved": "https://registry.npmjs.org/lodash.get/-/lodash.get-4.4.2.tgz", "resolved": "https://registry.npmjs.org/lodash.get/-/lodash.get-4.4.2.tgz",
...@@ -734,6 +791,24 @@ ...@@ -734,6 +791,24 @@
"backoff": "~2.5.0" "backoff": "~2.5.0"
} }
}, },
"redis-commands": {
"version": "1.4.0",
"resolved": "https://registry.npmjs.org/redis-commands/-/redis-commands-1.4.0.tgz",
"integrity": "sha512-cu8EF+MtkwI4DLIT0x9P8qNTLFhQD4jLfxLR0cCNkeGzs87FN6879JOJwNQR/1zD7aSYNbU0hgsV9zGY71Itvw=="
},
"redis-errors": {
"version": "1.2.0",
"resolved": "https://registry.npmjs.org/redis-errors/-/redis-errors-1.2.0.tgz",
"integrity": "sha1-62LSrbFeTq9GEMBK/hUpOEJQq60="
},
"redis-parser": {
"version": "3.0.0",
"resolved": "https://registry.npmjs.org/redis-parser/-/redis-parser-3.0.0.tgz",
"integrity": "sha1-tm2CjNyv5rS4pCin3vTGvKwxyLQ=",
"requires": {
"redis-errors": "^1.0.0"
}
},
"restify": { "restify": {
"version": "7.2.1", "version": "7.2.1",
"resolved": "https://registry.npmjs.org/restify/-/restify-7.2.1.tgz", "resolved": "https://registry.npmjs.org/restify/-/restify-7.2.1.tgz",
...@@ -926,6 +1001,11 @@ ...@@ -926,6 +1001,11 @@
"tweetnacl": "~0.14.0" "tweetnacl": "~0.14.0"
} }
}, },
"standard-as-callback": {
"version": "1.0.1",
"resolved": "https://registry.npmjs.org/standard-as-callback/-/standard-as-callback-1.0.1.tgz",
"integrity": "sha512-izxEITSyc7S+5oOiF/URiYaNkemPUxIndCNv66jJ548Y1TVxhBvioNMSPrZIQdaZDlhnguOdUzHA/7hJ3xFhuQ=="
},
"stream-transform": { "stream-transform": {
"version": "0.2.2", "version": "0.2.2",
"resolved": "https://registry.npmjs.org/stream-transform/-/stream-transform-0.2.2.tgz", "resolved": "https://registry.npmjs.org/stream-transform/-/stream-transform-0.2.2.tgz",
......
...@@ -11,6 +11,7 @@ ...@@ -11,6 +11,7 @@
"license": "ISC", "license": "ISC",
"dependencies": { "dependencies": {
"config": "^1.30.0", "config": "^1.30.0",
"ioredis": "^4.2.0",
"jsonwebtoken": "^8.3.0", "jsonwebtoken": "^8.3.0",
"jwt-verify": "git+https://nexpienpm:CCqLQjg4ytvzN7QbssUV@dev.nexpie.com/npm/jwt-verify.git", "jwt-verify": "git+https://nexpienpm:CCqLQjg4ytvzN7QbssUV@dev.nexpie.com/npm/jwt-verify.git",
"lru-cache": "^4.1.3", "lru-cache": "^4.1.3",
......
var Redis = require('ioredis')
var redis = new Redis()
var pub = new Redis()
function on_register_redis(deviceid) { // first time to access on authhook auth_on_register
return new Promise((resolve, reject) => {
var information = setValue(deviceid)
redis.hset(information.keys, 'status', information.status, 'register_on', information.register_on, 'last_check', information.last_check, function (err, res) {
resolve(!res) // 0 is ok, 1 is no => if ok is 0 then not 0 = 1
})
})
}
module.exports.on_register_redis = on_register_redis
function setValue(deviceid) {
var dateNow = Math.floor(Date.now() / 1000)
var keys = 'deviceid:' + deviceid
var status = true
var register_on = dateNow
var last_check = dateNow
return {
keys: keys,
status: status,
register_on: register_on,
last_check: last_check
}
}
\ No newline at end of file
var Redis = require('ioredis')
var redis = new Redis()
redis.subscribe('clientStatus')
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment