创建项目

初始化为node项目

$npm init

 

安装redis

 

安装@types/node, @types/redis, typescript

 

初始化TypeScript

 

配置tsconfig.json

 

 

参考package.json

{

"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"

}

}

 

新建文件App.ts

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);

});

 

 

编译App

$ npm run dev

 

运行App

$ npm start

 

 

参考资源:

https://github.com/DefinitelyTyped/DefinitelyTyped/blob/master/types/redis/redis-tests.ts

https://npm.taobao.org/package/redis

 

 

 

 

 

最新文章

  1. json文件
  2. 百度文库下载器 V2.3.4.3 支持豆丁百度文库道客巴巴
  3. web应用程序测试方法和测试技术详述
  4. 转:GROUPING SETS、ROLLUP、CUBE
  5. ADF_Database Develop系列1_设计数据库表之Diagram/Tables/View/Sequence
  6. WIN8+VS2013编写发布WCF之三(调用)
  7. WPF——绑定数据库数据(Listview)
  8. boost总结之variant
  9. 【JQuery学习历程】1.初识JQuery
  10. 【IE6的疯狂之十二】一个display:none引起的3像素的BUG
  11. 安装Sphere v2.7 遇到的问题
  12. [Swift]LeetCode93. 复原IP地址 | Restore IP Addresses
  13. 雷林鹏分享:CodeIgniter 数据库操作
  14. Kafka(2)--kafka基本原理之消息的分发与接收
  15. (二 -5) 天猫精灵接入Home Assistant-自动发现Mqtt设备--电风扇
  16. p86商空间也是Banach空间
  17. namecheap域名设置Cloudflare为第三方DNS
  18. JavaScript 对象拷贝研究
  19. python全栈开发day48-jqurey自定义动画,jQuery属性操作,jQuery的文档操作,jQuery中的ajax
  20. MAC下调试JSON接口的工具(HTTP抓包工具)

热门文章

  1. javascript之系统对话框
  2. 【总结整理】JQuery基础学习---动画
  3. 5、预测和鉴定miRNA的靶基因
  4. 使用CocoaLumberjack时,自定义的log文件名
  5. 20.Ecshop 2.x/3.x SQL注入/任意代码执行漏洞
  6. 1.jQuery入口函数 与javaScript入口函数
  7. kingadmin
  8. 浅谈JavaScript--事件委托与事件监听
  9. 【转】C# 使用正则表达式去掉字符串中的数字,或者去掉字符串中的非数字
  10. 洛谷P1607 [USACO09FEB]庙会班车Fair Shuttle