购物车超时
如果我正在编写一个票务系统,客户选择票并且我想将其锁定 3 分钟(如票务大师),直到他们完成订单或时间用完,我该怎么做?我想避免客户放弃会话/应用程序崩溃,然后最终将票证永远锁定在数据库中。
我在 ORM 和 C# 中使用 nHibernate。
If I'm writing a ticketing system, where the customer selects the ticket and I want to lock it for 3 minutes (like ticket master) until they complete their order or time runs out, how could I do this? I want to avoid having a customer abandon their session/application crash and then end up with the ticket locked in the database forever.
I'm using nHibernate for my ORM and C#.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
只需有一个单独的表来保存所有当前的预订即可。例如:
这将不依赖于会话。您甚至不需要删除过期的记录,当新客户查询机票时,可以找到所有可用的座位,而预订表中不存在这些座位,且过期日期 > 。现在。
避免更复杂的定时事件系统和类似的事情,保持简单。
Just have a separate table that holds all current reservations. For example:
This will then not be dependant on sessions. You don't even need to delete expired records, when a new customer queries a ticket find all seats that are available where they dont exist in the reservations table where the expirydate > now.
Avoid more complex systems of timed events and things like that, keep it simple.
拥有票证过期服务,定期解锁过期票证锁。
记录到期时间和票证(可能带有会话 ID)。
当不再需要时,订单可以将其删除,或者如果出现故障,它将自动解锁。
Have a ticket expiry service that periodically unlocks expired ticket locks.
Record the expiry time and the ticket (possibly with a session id).
The the order could remove this when no longer needed or in case of faliure it will be automatically unlocked.
如果您可以识别每个票证,您可以将锁定信息分配给该票证,其中包含有关用户、订单等的数据,当然还有保存锁定到期时间的时间戳。
如果其他用户想要选择该票证,您只需检查此时间戳以查看锁定是否已过期。
If you can identify each ticket, you can assign locking information to this ticket with data about user, order, etc and of course - timestamp wich holds time when lock expires.
If another user wants to select the ticket, you just need to check this timestamp to see if the lock has expired.