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 :: auto generate component angular 
Javascript :: change icon on click angular 
Javascript :: $(...).Datatables is not a function 
Javascript :: javascript constants 
Javascript :: Map put() method 
Javascript :: history.pushstate 
Javascript :: how to add css based on route react 
Javascript :: skip method js 
Javascript :: console.log() Syntax 
Javascript :: window parent frame 
Javascript :: javascript image preview before upload 
Javascript :: js add margin with variable 
Javascript :: deploying multiple sites in firebase 
Javascript :: update a value from array in redux state 
Javascript :: how to control where the text cursor on div 
Javascript :: crud operation react js 
Javascript :: table like another component in react native 
Javascript :: event loop javascript 
Javascript :: error: Error: Unable to resolve module `crypto` from `node_modulescrypto-jscore.js`: crypto could not be found within the project. 
Javascript :: js code for webpage download progress bar 
Javascript :: enzyme airnb 
Javascript :: react rating 
Javascript :: Iterating or loop through the elements of an array is with a for loop (for): 
Javascript :: combineReducers. 
Javascript :: Javascript get / print current path 
Javascript :: createtextnode javascript 
Javascript :: javascript set query parameters in url 
Javascript :: padstart in javascript 
Javascript :: how to add comment in javascript 
Javascript :: http error 406 
ADD CONTENT
Topic
Content
Source link
Name
3+1 =