node.js express.js sequelize redis cache

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.get(redisKey); if (cacheData) return cacheData; // not empty return cache data ...

2020-07-03 · 1 min · 153 words · Me

node.js redis special delete del

https://github.com/luin/ioredis``` const Redis = require(‘ioredis’); const redis = new Redis(); const delScript = local all_keys = {}; local keys = {}; local done = false; local cursor = "0" repeat local result = redis.call("SCAN", cursor, "match", KEYS[1], "count", KEYS[2]) cursor = result[1]; keys = result[2]; for i, key in ipairs(keys) do all_keys[#all_keys+1] = key; end if cursor == "0" then done = true; end until done for i, key in ipairs(all_keys) do redis.call("DEL", key); end return true; ; ...

2020-07-02 · 1 min · 97 words · Me

javascript functions parm default value

https://stackoverflow.com/questions/6600868/set-default-value-of-javascript-object-attributes``` // default num: 0, unit: ‘pics’ function items(op) { const { num, unit } = Object.assign({}, { num: 0, unit: ‘pics’}, op); }

2020-06-30 · 1 min · 24 words · Me

mysql virtual colume alert

ALTER TABLE `user` ADD `last name` VARCHAR(50) AS ( case `name` when admin then 0 else CONCAT(`name`, 'user') end ) ;

2020-06-24 · 1 min · 21 words · Me

vs code vscode remote ssh Error: EACCES: permission denied

vscode remote ssh Error: EACCES: permission denied https://github.com/microsoft/vscode/issues/48659 1. make sure that sudo -u newuser -i works in a regular ssh session without requesting a password 2. remove “-o RemoteCommand=none” and “bash” from extension.js like so``` sed -i s/"-o RemoteCommand=none"/""/ ~/.vscode/extensions/ms-vscode-remote.remote-ssh-*/out/extension.js sed -i s/“bash”/""/ ~/.vscode/extensions/ms-vscode-remote.remote-ssh-*/out/extension.js 3\. create an ssh config entry with a RemoteCommand like this one: Host pi-for-newuser Hostname pi User pi RemoteCommand sudo -u newuser -i [![](https://1.bp.blogspot.com/-FXedlr85sQM/Xuw5z-9I5kI/AAAAAAAAZso/-0XXb2R1LWI7qAlYkZvN31GjVuKov9e_gCK4BGAsYHg/w625-h483/dddddd.jpg)](https://1.bp.blogspot.com/-FXedlr85sQM/Xuw5z-9I5kI/AAAAAAAAZso/-0XXb2R1LWI7qAlYkZvN31GjVuKov9e_gCK4BGAsYHg/s1606/dddddd.jpg) Get Problem: mesg: ttyname failed: Inappropriate ioctl for device [https://unix.stackexchange.com/questions/48527/ssh-inside-ssh-fails-with-stdin-is-not-a-tty](https://unix.stackexchange.com/questions/48527/ssh-inside-ssh-fails-with-stdin-is-not-a-tty) RequestTTY Yes RemoteCommand sudo -i ...

2020-06-19 · 1 min · 84 words · Me