http://liu-xin.me/2017/03/24/%E8%AE%A9%E5%86%99%E5%85%A5%E6%95%B0%E6%8D%AE%E5%BA%93%E7%9A%84%E6%95%B0%E6%8D%AE%E8%87%AA%E5%8A%A8%E5%86%99%E5%85%A5%E7%BC%93%E5%AD%98/```
const to = require(‘await-to-js’).default;
const Redis = require(‘ioredis’);
const redis = new Redis(ooxxooxx);
function Cache() {}
Cache.get = async function(key) {
const [err, res] = await to(redis.get(key));
if (err) {console.error(‘REDIS::Cache::get]’, err); return null;}
return JSON.parse(res);
};
Cache.set = async function(key, value) {
value = JSON.stringify(value);
const [err] = await to(redis.set(key, value));
if (err) {console.error(‘REDIS::Cache::set]’, err); }
};
//
// sequelize.query
//
async function CacheSequelizeQuery(sequelize, sql, params, redisKey) {
const cacheData = await Cache.
https://sematext.com/blog/expressjs-best-practices/```
const express = require(‘express’)
const app = express()
const redis = require(‘redis’)
const redisClient = redis.createClient(6379)
async function getSomethingFromDatabase (req, res, next) {
try {
const { id } = req.params;
const data = await database.query()
// Set data to Redis
redisClient.setex(id, 3600, JSON.stringify(data))
res.status(200).send(data) } catch (err) {
console.error(err)
res.status(500)
}
}
function cache (req, res, next) {
const { id } = req.
https://www.youtube.com/watch?v=jI4K7L-LI58
ajv schema to apidoc schema
https://github.com/willfarrell/apidoc-plugin-schema
required can’t product doc.
converter
https://github.com/apidoc/apidoc#converter
to swagger
https://github.com/fsbahman/apidoc-swagger
postman collection to apidoc
https://github.com/bonzzy/docmaster
RestClient -> curl -> postman
https://expressjs.com/en/advanced/best-practice-security.html