【文件属性】:
文件名称:distributed_mutex
文件大小:7KB
文件格式:ZIP
更新时间:2021-03-19 10:12:05
Ruby
分布式Mutex
使用Redis的简单分布式锁。
安装(尚未上传到rubygems)
gem install distributed_mutex
或者,如果您正在使用Rails,则可以通过Bundler安装。将此行添加到您的应用程序的Gemfile中:
gem 'distributed_mutex'
然后执行:
bundle
基本用法
redis = Redis . new
key = "foo:bar"
mutex = DistributedMutex . new ( redis , key )
# Not wait for a lock
mutex . synchronize { 1 + 1 == 2 }
# Wait for a lock
mutex . synchronize ( wait : true ) { 1 + 1 == 2 }
# Extend a existed
【文件预览】:
distributed_mutex-main
----Rakefile(281B)
----.github()
--------workflows()
----test()
--------helper.rb(118B)
--------distributed_mutex_test.rb(2KB)
----.rubocop.yml(104B)
----LICENSE(1KB)
----.gitignore(12B)
----lib()
--------distributed_mutex.rb(2KB)
--------distributed_mutex()
----README.md(940B)
----distributed_mutex.gemspec(866B)