index.js
const redis = require("redis");
// 创建客户端
const redisClient = redis.createClient(6379, "127.0.0.1");
redisClient.on("error", (err) => {
console.error(err);
});
// 测试
redisClient.set("myname", "wcd2", redis.print);
redisClient.get("myname", (err, val) => {
if (err) {
console.error(err);
return;
}
console.log("val", val);
// 退出
redisClient.quit();
});
package.json
{
"name": "redis-test",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"redis": "^2.8.0"
}
}