Skip to Content
Node与Express开发(第2版)
book

Node与Express开发(第2版)

by Ethan Brown
June 2021
Intermediate to advanced
290 pages
9h 21m
Chinese
Posts & Telecom Press
Content preview from Node与Express开发(第2版)
146
|
第
13
章
要了(否则,当用户试图再次对同一个度假订阅通知的时候,
INSERT
命令就会出错)。
现在我们已经看到了使用对象数据库和关系型数据库来实现相同目的的完整例子。应该清
楚的是,数据库的功能都是以一致并可扩展的方式来存储、获取和更新数据。因为功能一
样,所以可以创建一个抽象层,从而选择不同的数据库技术。最后一个可能会用到数据库
的地方是持久化
Session
存储,这个第
9
章已经提到过了。
13.4
 使用数据库存储
Session
正如第
9
章所讨论的,在生产环境中使用内存作为
Session
数据的存储是不合适的。幸运
的是,使用数据库作为
Session
存储是很容易的。
对于
Session
存储
,虽然可以使用现有的
MongoDB
或
PostgreSQL
数据库,但是它们功能
太强大了,恐怕会过犹不及。这里其实是键值数据库的完美应用场景。当我写到这里时,
可以用于
Session
存储的主流键值数据库是
Redis
和
Memcach
ed
。为了跟本章的其他示例
一致,我们将使用一个
Redis
数据库的免费在线服务。
先去
Redis Labs
创建一个账号
。然后创建一个免费的订阅和计划。在计划中选择
Cache
,
并给数据库起个名字,其余设置按默认的就可以。
接下来会转到数据库详情页面,当我写到这里时,关键信息需要若干秒才能出来,所以
需要一点儿耐心。你需要的是
Endpoint
字段和
Access
Control & Security
下面的
Redis
密
码(默认是隐藏的,但紧跟着它有一个小按钮,点击即可见)。把这些信息放入
.credentials ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.

Read now

Unlock full access

More than 5,000 organizations count on O’Reilly

AirBnbBlueOriginElectronic ArtsHomeDepotNasdaqRakutenTata Consultancy Services

QuotationMarkO’Reilly covers everything we've got, with content to help us build a world-class technology community, upgrade the capabilities and competencies of our teams, and improve overall team performance as well as their engagement.
Julian F.
Head of Cybersecurity
QuotationMarkI wanted to learn C and C++, but it didn't click for me until I picked up an O'Reilly book. When I went on the O’Reilly platform, I was astonished to find all the books there, plus live events and sandboxes so you could play around with the technology.
Addison B.
Field Engineer
QuotationMarkI’ve been on the O’Reilly platform for more than eight years. I use a couple of learning platforms, but I'm on O'Reilly more than anybody else. When you're there, you start learning. I'm never disappointed.
Amir M.
Data Platform Tech Lead
QuotationMarkI'm always learning. So when I got on to O'Reilly, I was like a kid in a candy store. There are playlists. There are answers. There's on-demand training. It's worth its weight in gold, in terms of what it allows me to do.
Mark W.
Embedded Software Engineer

You might also like

面向对象的思考过程(原书第5版)

面向对象的思考过程(原书第5版)

马特 魏斯费尔德
精通模块化JavaScript

精通模块化JavaScript

Nicolás Bevacqua
前端架构设计

前端架构设计

Micah Godbolt

Publisher Resources

ISBN: 9787115565099