2024年7月将完成这个替代和包件
谷歌云数据存储会话
@ google- cloud/ 连接数据存储器 是一个 谷歌云数据库 以 @ google- cloud/ 数据存储器。 。 。 .
说明: Cloud Datastore是一个持续,分布,交易的数据库. 通常,为会话选择不同的存储解决方案更合适 例如Memcache 或 Redis , 因为它们的设计能提供更快的操作 使用大小写.
安装
npm install @google-cloud/connect-datastore
配置
你一定有谷歌云项目和证书.
见 gcloud 节点的文档 设置认证.
用法示例
const {Datastore} = require('@google-cloud/datastore');
const {DatastoreStore} = require('@google-cloud/connect-datastore');
const express = require('express');
const session = require('express-session');
const app = express();
app.use(session({
store: new DatastoreStore({
kind: 'express-sessions',
// Optional: expire the session after this many milliseconds.
// note: datastore does not automatically delete all expired sessions
// you may want to run separate cleanup requests to remove expired sessions
// 0 means do not expire
expirationMs: 0,
dataset: new Datastore({
// For convenience, @google-cloud/datastore automatically looks for the
// GCLOUD_PROJECT environment variable. Or you can explicitly pass in a
// project ID here:
projectId: process.env.GCLOUD_PROJECT,
// For convenience, @google-cloud/datastore automatically looks for the
// GOOGLE_APPLICATION_CREDENTIALS environment variable. Or you can
// explicitly pass in that path to your key file here:
keyFilename: process.env.GOOGLE_APPLICATION_CREDENTIALS
})
}),
secret: 'my-secret'
}));
过期
如果在创建时间和当前之间获取三角形的会话 超过过期时间的会话,不会返回并且会 而不是被摧毁.
数据存储不支持 a ttl,仅在会话中删除符号
已获取。 您可能想要执行偶尔删除的逻辑
过期的会话 .
捐款
- 见 捐款额
许可证
- Apache 2. 0 - 见 自由主义