




























初始化为node项目
$npm init
安装redis
安装@types/node, @types/redis, typescript
{
"name": "redis-demo",
"version": "1.0.0",
"description": "",
"main": "app.js",
"scripts": {
"build": "tsc",
"dev": "tsc -w",
"start": "node .\\build\\app.js",
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC",
"devDependencies": {
"@types/node": "^9.6.0",
"@types/redis": "^2.8.6",
"typescript": "^2.7.2"
},
"dependencies": {
"redis": "^2.8.0"
}
}
import * as redis from "redis"
console.log("redis node.js demo!");
let client = redis.createClient();
client.on("error", function (err) {
console.log("Error " + err);
});
client.set("hello", "redis", redis.print);
client.get("hello", (err, reply) => {
console.log("Error %s ", err);
console.log("Reply %s ", reply);
});
$ npm run dev
$ npm start
https://github.com/DefinitelyTyped/DefinitelyTyped/blob/master/types/redis/redis-tests.ts
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。