小编cga*_*uss的帖子

如何使用Node.js以70个请求/秒分发唯一的优惠券代码

当我们启动交易时,我会运行一个可以看到50-70个请求/秒的优惠券网站(我们每天多次推出20多个交易).当交易上线时,我们的用户按下按钮即可获得特定产品的优惠券,该优惠券通过ajax https请求提供独特的优惠券代码.每张优惠券只能兑换一次.

我的问题是,在这些时候如此高的流量,可以将相同的优惠券分发给多个用户.这是不好的,因为只有其中一个人能够实际兑换优惠券,留给另一方的糟糕用户体验.

我将所有优惠券信息存储在IBM Bluemix托管的node.js服务器上的内存中的对象中.我想这可以让我快速处理请求.

我如何存储优惠券信息:

global.coupons = {};

//the number of coupons given for each product
global.given = {};

/*   Setting the coupon information */

//....I query my database for the products to be given today 

for(var i = 0; i < results.length; i++){
     var product = results[i];

     //add only the coupons to give today to the array
     var originalCoups = product.get('coupons');
     var numToTake = product.get('toGivePerDay');

      if(product.get('givenToday') > 0){
           numToTake = numToTake - product.get('givenToday');
      }
      // Example coupon array …
Run Code Online (Sandbox Code Playgroud)

javascript ajax object node.js

9
推荐指数
1
解决办法
1126
查看次数

标签 统计

ajax ×1

javascript ×1

node.js ×1

object ×1