diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..c2658d7 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +node_modules/ diff --git a/index.js b/index.js new file mode 100644 index 0000000..2a70ecb --- /dev/null +++ b/index.js @@ -0,0 +1,60 @@ +/* ushio-env +* +* By iotcat (https://iotcat.me) +* MIT Licensed +* +*/ +module.exports = async (o_params) => { + + /* params process */ + var params = { + redis: { + host: "redis", + port: 6379 + }, + debug: { + format: (time, content) => { + return `Ushio-env: ${tool.time.format(time)} :: ${content}`; + }, + output: console.log, + + } + }; + + Object.assign(params, o_params); + + /* output obj */ + var o = {}; + + /* tool func */ + var tool = { + time: { + format: date => { + let year=date.getFullYear(); + let mon=date.getMonth()+1; + let da=date.getDate(); + let h=date.getHours(); + let m=date.getMinutes(); + let s=date.getSeconds(); + return year+'-'+mon+'-'+da+' '+h+':'+m+':'+s; + } + } + } + + + /* exec */ + + /* redis */ + var redis = require('redis').createClient(params.redis.port, params.redis.host); + redis.on('error', err => { + params.debug.output(params.debug.format(new Date(), err)); + }); + + + + + return new Promise((resolve, reject) => { + o.redis = redis; + + }); +} diff --git a/package.json b/package.json new file mode 100644 index 0000000..b949831 --- /dev/null +++ b/package.json @@ -0,0 +1,12 @@ +{ + "name": "ushio-env", + "version": "1.0.0", + "description": "Ushio env for node-js", + "main": "index.js", + "repository": "https://github.com/IoTcat/ushio-env.git", + "author": "iotcat ", + "license": "MIT", + "dependencies": { + "redis": "^3.0.2" + } +} diff --git a/yarn.lock b/yarn.lock new file mode 100644 index 0000000..92ab23f --- /dev/null +++ b/yarn.lock @@ -0,0 +1,35 @@ +# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY. +# yarn lockfile v1 + + +denque@^1.4.1: + version "1.4.1" + resolved "https://registry.yarnpkg.com/denque/-/denque-1.4.1.tgz#6744ff7641c148c3f8a69c307e51235c1f4a37cf" + integrity sha512-OfzPuSZKGcgr96rf1oODnfjqBFmr1DVoc/TrItj3Ohe0Ah1C5WX5Baquw/9U9KovnQ88EqmJbD66rKYUQYN1tQ== + +redis-commands@^1.5.0: + version "1.5.0" + resolved "https://registry.yarnpkg.com/redis-commands/-/redis-commands-1.5.0.tgz#80d2e20698fe688f227127ff9e5164a7dd17e785" + integrity sha512-6KxamqpZ468MeQC3bkWmCB1fp56XL64D4Kf0zJSwDZbVLLm7KFkoIcHrgRvQ+sk8dnhySs7+yBg94yIkAK7aJg== + +redis-errors@^1.0.0, redis-errors@^1.2.0: + version "1.2.0" + resolved "https://registry.yarnpkg.com/redis-errors/-/redis-errors-1.2.0.tgz#eb62d2adb15e4eaf4610c04afe1529384250abad" + integrity sha1-62LSrbFeTq9GEMBK/hUpOEJQq60= + +redis-parser@^3.0.0: + version "3.0.0" + resolved "https://registry.yarnpkg.com/redis-parser/-/redis-parser-3.0.0.tgz#b66d828cdcafe6b4b8a428a7def4c6bcac31c8b4" + integrity sha1-tm2CjNyv5rS4pCin3vTGvKwxyLQ= + dependencies: + redis-errors "^1.0.0" + +redis@^3.0.2: + version "3.0.2" + resolved "https://registry.yarnpkg.com/redis/-/redis-3.0.2.tgz#bd47067b8a4a3e6a2e556e57f71cc82c7360150a" + integrity sha512-PNhLCrjU6vKVuMOyFu7oSP296mwBkcE6lrAjruBYG5LgdSqtRBoVQIylrMyVZD/lkF24RSNNatzvYag6HRBHjQ== + dependencies: + denque "^1.4.1" + redis-commands "^1.5.0" + redis-errors "^1.2.0" + redis-parser "^3.0.0"