Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

redis nodejs

/* npm install redis */

const redis = require("redis");
const client = redis.createClient();

client.on("error", function(error) {
  console.error(error);
});

client.set("key", "value", redis.print);
client.get("key", redis.print);
Comment

node-redis

// node-redis to promise, because node-redis not support promise

import bluebird from 'bluebird'
import { Commands, createClient } from 'redis'

const client = createClient({
	host: process.env.REDIS_HOST,
	port: parseInt(process.env.REDIS_PORT),
	password: process.env.REDIS_PASSWORD
})

let redisCon: Commands<any>
;(async (redis) => {
	const redisPromise = await bluebird.resolve<Commands<any>>(redis)
	redisCon = redisPromise
})(client)

export { redisCon }
Comment

nodejs redis

const redis = require('redis')
const client = redis.createClient()

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

client.set('string key', 'string val', redis.print)
client.hset('hash key', 'hashtest 1', 'some value', redis.print)
client.hset(['hash key', 'hashtest 2', 'some other value'], redis.print)

client.hkeys('hash key', (err, replies) => {
  console.log(`${replies.length} replies:`)

  replies.forEach((reply, i) => {
    console.log(`    ${i}: ${reply}`)
  })

  client.quit()
})
Comment

PREVIOUS NEXT
Code Example
Javascript :: post xml with axios nodejs 
Javascript :: js capitalize word 
Javascript :: how hide .html in url 
Javascript :: es6 array sum javascript 
Javascript :: how to add new key value to json object in javascript 
Javascript :: axios cancel request 
Javascript :: js check if function is a constructor 
Javascript :: bootstrap time picker 12 hour format 
Javascript :: js text to html 
Javascript :: slice javascript string 
Javascript :: nodejs event 
Javascript :: usenavigate in react 
Javascript :: javascript log to console 
Javascript :: how to set input date to today date on initialization 
Javascript :: jest expect not contain 
Javascript :: ifsc code validation formik 
Javascript :: how to get on click id in event 
Javascript :: js make id 
Javascript :: tolocaledatestring format dd-mm-yyyy 
Javascript :: how we link external js file in laravel 9 project 
Javascript :: jquery .click function call 
Javascript :: javascript random element from array 
Javascript :: javascript convert object to querystring 
Javascript :: switch js 
Javascript :: axios send file 
Javascript :: javascript object destructuring 
Javascript :: continuous scrolling js 
Javascript :: add items to a list in a document monoose 
Javascript :: json data 
Javascript :: js isset variable 
ADD CONTENT
Topic
Content
Source link
Name
1+4 =