秒杀系统设计-流程图


        // Redis中使用Lua脚本校验并减扣库存
        StringBuilder script = new StringBuilder();
        script.append("if (redis.call('EXISTS', KEYS[1]) == 1) then");
        script.append("   if (redis.call('GET', KEYS[1]) - ARGV[1] >=0) then");
        script.append("       redis.call('DECRBY', KEYS[1], ARGV[1]);");
        script.append("       return 1");
        script.append("   else");
        script.append("       return -1;");
        script.append("   end;");
        script.append("end;");
        script.append("return -2;");