LoginSignup
0
0

More than 3 years have passed since last update.

Node.js: bluebird を使って Redis のデータを読む

Last updated at Posted at 2020-12-30

次のプログラムを bluebird を使って書き換えました。
Node.js: Async/Await を使って Redis のデータを読む

ライブラリーのインストール

sudo npm install -g bluebird
bluebird_read.js
#! /usr/bin/node
// ---------------------------------------------------------------
//
//  bluebird_read.js
//
//                  Dec/30/2020
// ---------------------------------------------------------------
'use strict'

const bluebird = require("bluebird")
const redis = require('redis')
bluebird.promisifyAll(redis.RedisClient.prototype)
bluebird.promisifyAll(redis.Multi.prototype)

// ---------------------------------------------------------------
async function proc01 ()
{
    const redisUrl = 'redis://127.0.0.1:6379'
    const client = redis.createClient(redisUrl)

    const keys = await client.keysAsync('*')

    keys.forEach(async function(key,index)
        {
        const value = await client.getAsync(key)
        console.log(key,value)
        })

    await client.quitAsync()
}

// ---------------------------------------------------------------
console.error ("*** 開始 ***")
proc01()
console.error ("*** 終了 ***")

// ---------------------------------------------------------------

実行スクリプト

export NODE_PATH=/usr/lib/node_modules
./bluebird_read.js
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0