0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

Node.js: Redis のキーの一覧を取得

Last updated at Posted at 2020-01-17

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

sudo npm install -g redis

プログラム

redis_list.js
#! /usr/local/bin/node
// ---------------------------------------------------------------
//	redis_list.js
//
//					Mar/25/2023
//
// ---------------------------------------------------------------
'use strict'

const redis = require('redis')

// ---------------------------------------------------------------
async function main()
{
	const client = redis.createClient()

	await client.connect()

	const keys = await client.keys('*')
	console.log (keys)
	console.log("keys.length = " + keys.length)
	console.log ("keys[0] = " + keys[0])

	await client.disconnect()

	console.error ("*** 終了 ***")
}

// ---------------------------------------------------------------
console.error ("*** 開始 ***")
main()

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

実行結果

$ export NODE_PATH=/usr/local/lib/node_modules
$ ./redis_list.js
*** 開始 ***
[
  't1859', 't1858',
  't1857', 't1855',
  't1851', 't1853',
  't1852', 't1854',
  't1856'
]
keys.length = 9
keys[0] = t1859
*** 終了 ***

確認したバージョン

$ node --version
v22.3.0

関連ページ
Node.js: Redis のデータを読む

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?