Skip to content

Commit

Permalink
docs: uniCloud
Browse files Browse the repository at this point in the history
  • Loading branch information
Wangyaqi committed Nov 23, 2020
1 parent e0c6185 commit d2f4626
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
29 changes: 29 additions & 0 deletions docs/uniCloud/faq.md
Original file line number Diff line number Diff line change
Expand Up @@ -165,3 +165,32 @@ uniCloud服务商为阿里云时支持配置全球加速,步骤如下:
4. 选择不使用的账号登录之后注销即可,参考文档:[注销腾讯云账号](https://cloud.tencent.com/document/product/378/30253)

同时,如果付费购买腾讯云服务空间,每个账号可以最多拥有50个腾讯云服务空间(注意其中仅有一个享受免费额度)。

### 高并发下简单的防止超卖

高并发时很多用户同时对一条数据读写,很容易造成数据混乱,表现在秒杀抢购等场景就是超卖。以秒杀为例,开发者可以从扣除库存这步入手对超卖进行很大程度的限制,下面是一个简单的示例

```js
// 云函数
const db = uniCloud.database()
const dbCmd = db.command
exports.main = async function(event){
const transaction = await db.startTransaction()
// 其他业务逻辑...
// 库存减一
const reduceRes = await db.collection('goods').where({
_id: 'goods_id', // 商品ID
stock: dbCmd.gt(1) // 限制库存大于1的才允许扣除库存
}).update({
stock: dbCmd.inc(-1)
})
if(reduceRes.updated === 0) { // 如果没成功更新库存就认为下单失败
await transaction.rollback()
return {
code: 1001,
message: '下单失败'
}
}
// 其他业务逻辑...
}
```
4 changes: 4 additions & 0 deletions docs/uniCloud/price.md
Original file line number Diff line number Diff line change
Expand Up @@ -127,3 +127,7 @@ uniCloud提供包月、按量计费两种计费方式(仅腾讯云),具体
- 按量计费服务空间删除有次数限制,每个月最多删除一次,每个账号一共可以删除4次,删除之前需要关闭前端网页托管服务并删除所有云端资源(包括云函数、数据库、云存储)
- 按量计费是延迟结算,可能存在余额超支的情况,故创建按量付费服务空间时,需支付一定的保证金,用以抵消超支结算的情况。如果您不再申请使用uniCloud服务,可以申请退还保证金。
- 目前使用腾讯云包月套餐会默认自动续费,如果包月套餐到期时uniCloud腾讯云账户余额够用则自动从余额中扣除一个月的费用,近期会提供关闭选项

**关于云函数1000并发的说明**

以云函数运行(计费时间)200ms为例,1000并发的云函数,每秒处理1000*(1/0.2) = 5000次请求,即QPS为5000

0 comments on commit d2f4626

Please sign in to comment.