- 'use strict'
- const redis = require('redis')
- // 接続情報
- const config = {
- host: '127.0.0.1',
- port: 6379
- }
- // 接続
- const client = redis.createClient(config)
- // データの登録
- client.set('key', 'value')
- // データの取得と表示
- client.get('key', (err, reply) => {
- console.log(reply)
- })
- // データの削除
- client.del('key')
- // 削除されているか確認
- client.get('key', (err, reply) => {
- console.log(reply)
- })
- // 切断
- client.quit()
- 'use strict'
- const redis = require('redis')
- // 接続情報
- const config = {
- host: '127.0.0.1',
- port: 6379
- }
- // 接続
- const client = redis.createClient(config)
- // データの登録
- client.set('key', 'value1')
- // データの取得と表示
- client.get('key', (err, reply) => {
- console.log(reply)
- })
- // データベース切り替え
- client.select(1)
- // 登録と検索
- client.set('key', 'value2')
- client.get('key', (err, reply) => {
- console.log(reply)
- })
- // 切断
- client.quit()
- 'use strict'
- const redis = require('redis')
- // 接続情報
- const config = {
- host: '127.0.0.1',
- port: 6379,
- db: 1 // db:1に接続
- }
- // 接続
- const client = redis.createClient(config)
- // データの取得と表示
- client.get('key', (err, reply) => {
- console.log(reply)
- })
- // 切断
- client.quit()
Author:symfo
blog形式だと探しにくいので、まとめサイト作成中です。
Symfoware まとめ