nodejs redis学习记录

nodejs连接redis

import redis from 'redis'

const redisLink = 'redis://127.0.0.1:6379'
const pwd = '289181'
const opts = {
    auth_pass: pwd,
}
const redisClient = redis.createClient(redisLink, opts)

redisClient
    .on('error', err => console.log('------ Redis connection failed ------' + err))
    .on('connect', () => console.log('------ Redis connection succeed ------'))

export default {
    redis: redis, 
    redisClient: redisClient, 
}

nodejs连接redis

npm install redis --save

var redis = require('redis');

var client = redis.createClient('6379', '127.0.0.1');

client.auth("password");
client.set('hello','This is a value');
client.expire('hello',10) //设置过期时间
client.exists('key') //判断键是否存在
client.del('key1')
client.get('hello');

Nodejs Redis 全部操作方法nodejs redis学习记录

 

上一篇:2021-04-23


下一篇:KickStart