README.mdgit
在大型游戏中常用分布式,分布式中由于游戏逻辑会常常游戏事务,借助redis某些特性咱们能够实现分布式锁和分布式事务。不少redis集群不支持redis的事务特性。
这个框架用来解决分布式服务器下redis集群事务失效的状况下多线程分布式锁和分布式锁,支持独占锁,共享锁,读写锁,而且支持事务提交失败状况下的回滚操做,让开发者能够有更多时间侧重游戏逻辑.github
可参考test下的entity.redis
- 生成事务缘由,GameTransactionCauseImpl里面构造.
- 生成锁实体,GameTransactionEntityFactoryImpl里面构造TimeMutexEntity.
- 提交锁实体跟事务,transactionService.commitTransaction里面提交.
- 后去事务提交结果,根据返回值作出判断.
可参考test下的read 能够设置默认是否成功读取到服务器
- 生成读取事务缘由GameTransactionCause里面已经构造好了.
- 生成读取锁实体GameTransactionEntityFactory里面已经构造好了.
- 提交读取锁实体跟事务transactionService.commitTransaction里面提交.
- 后去事务提交结果 根据返回值作出判断.
可参考test下的lockattchment能够设置默认是否成功读取到多线程
- 生成事务缘由,GameTransactionCauseImpl里面构造.
- 生成锁实体,GameTransactionEntityFactoryImpl里面构造.
- 生成锁标记内容 GameTransactionEntity对象获取GameTransactionLockInterface锁使用setContent
- 提交锁实体跟事务,transactionService.commitTransaction里面提交.
- 后去事务提交结果,根据返回值作出判断.
- 生成读取事务缘由GameTransactionCause里面构造.
- 生成读取锁实体GameTransactionEntityFactory里面构.
- 生成锁标记内容 GameTransactionEntity对象获取GameTransactionLockInterface锁使用setContent
- 提交读取锁实体跟事务transactionService.commitTransaction里面提交.
- 后去事务提交结果 根据返回值作出判断.
可参考test下的force
当锁存在的状况,延迟锁占用时间。
例子以下
1. 生成事务缘由,GameTransactionCauseImpl里面构造.
2. 生成锁实体,GameTransactionEntityFactoryImpl里面构造ForceEntity.
3. 提交锁实体跟事务,transactionService.commitTransaction里面提交.
4. 后去事务提交结果,根据返回值作出判断.框架
参考test下的testlock.
当锁存在的状况,延迟锁占用时间。
例子以下maven
- 生成事务缘由,GameTransactionCauseImpl里面构造.
- 生成锁实体,GameTransactionEntityFactoryImpl里面构造TestTimeMutexEntity.
- 提交锁实体跟事务,transactionService.commitTransaction里面提交.
- 后去事务提交结果,根据返回值作出判断.
参考test下的wait.当锁失败的状况下,会尝试每秒检查锁,直到设置的等待时间结束.例子以下分布式
- 生成事务缘由,GameTransactionCauseImpl里面构造.
- 生成锁实体,GameTransactionEntityFactoryImpl里面构造WaitMutexEntity.
- 提交锁实体跟事务,transactionService.commitTransaction里面提交.
- 后去事务提交结果,根据返回值作出判断.
参考test下的rollback.当事务提交失败的状况下,根据提交进度进行rollback.例子以下spa
- 生成事务缘由,GameTransactionCauseImpl里面构造.
- 生成锁实体,GameTransactionEntityFactoryImpl里面构造RollbackMutexEntity.
- 提交锁实体跟事务,transactionService.commitTransaction里面提交.
- 后去事务提交结果,根据返回值作出判断.
代码最后经过maven部署线程
- 做者qq 330258845
- QQ群310158485