数据库
首页 > 数据库> > nodejs redis学习记录

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 全部操作方法

 

标签:const,记录,nodejs,redis,redisClient,client,------
来源: https://www.cnblogs.com/pearlcity/p/14412671.html