Search
 
SCRIPT & CODE EXAMPLE
 

SHELL

redis cache start

sudo /etc/init.d/redis_6379 start
Comment

redis cache management

const redis = require('redis');
const config = require('../config');
const client = redis.createClient({
    host: config.redis.host,
    port: config.redis.port,
    password: config.redis.password 
});

const { promisify } = require('util');
const setAsyncEx = promisify(client.setex).bind(client);
const getAsync = promisify(client.get).bind(client);

client.on('error', err => {
    console.log('Error ' + err);
});

async function saveWithTtl(key, value, ttlSeconds = 60) {
  return await setAsyncEx(key, ttlSeconds, JSON.stringify(value)); 
}

async function get(key) {
  const jsonString = await getAsync(key);

  if (jsonString) {
    return JSON.parse(jsonString);
  }
}

module.exports = {
  saveWithTtl,
  get
}
Comment

redis cache management

const redis = require('redis');
const config = require('../config');
const client = redis.createClient({
    host: config.redis.host,
    port: config.redis.port,
    password: config.redis.password 
});

const { promisify } = require('util');
const setAsyncEx = promisify(client.setex).bind(client);
const getAsync = promisify(client.get).bind(client);

client.on('error', err => {
    console.log('Error ' + err);
});

async function saveWithTtl(key, value, ttlSeconds = 60) {
  return await setAsyncEx(key, ttlSeconds, JSON.stringify(value)); 
}

async function get(key) {
  const jsonString = await getAsync(key);

  if (jsonString) {
    return JSON.parse(jsonString);
  }
}

module.exports = {
  saveWithTtl,
  get
}
Comment

PREVIOUS NEXT
Code Example
Shell :: Save changes in a new branch git 
Shell :: debian 9 enable rc.local 
Shell :: Git command to Change Your Committer Name & Email per repository 
Shell :: docker ps not showing containers 
Shell :: how to push to new branch in github 
Shell :: git diff between two repos 
Shell :: force install deb file 
Shell :: powershell delete empty folders 
Shell :: git apply diff 
Shell :: mkdir -p parameter 
Shell :: powershell get-verb sorted by verb 
Shell :: how to remove a pushed file from git 
Shell :: install insomnia in ubuntu 
Shell :: uninstall django ubuntu 
Shell :: Custom Bash Shell 
Shell :: delete all mail terminal 
Shell :: bash rename multiple files pattern 
Shell :: grep word after match 
Shell :: ionic capacitor run ios 
Shell :: list of created ssh port forwarding 
Shell :: gitlab gradle project 
Shell :: sed delete line match 
Shell :: ubuntu default tmux shell 
Shell :: svg to png convert imagemagick 
Shell :: install kubernetes linux 
Shell :: git merge branch into another branch 
Shell :: merge branch to master 
Shell :: install flutter 
Shell :: git revert remote branch 
Shell :: download git branch 
ADD CONTENT
Topic
Content
Source link
Name
4+4 =