सर्वर से जुड़कर एक लॉक प्राप्त करने के बाद तुरंत छोड़ने का सबसे सरल प्रवाह है।
broker = Broker.connect(addr)
begin
broker.wait_ready(5)
ticket = broker.acquire("key", wait: 5, lease: 30)
ticket.release
puts "pass"
ensure
broker.close
endकई थ्रेड एक साथ खाता-वार लॉक से सुरक्षित रहते हुए जमा/निकासी दोहराने पर भी, सभी खातों की शेष राशि अंततः शुरुआती मान पर वापस आती है या नहीं, यह जाँचने का उदाहरण है।
def transaction(broker, balances, account, delta, log)
key = "account-#{account}"
ticket =
begin
broker.acquire(key, wait: WAIT, lease: LEASE)
rescue StandardError => e
log.error("account #{account} acquire failed: #{e}")
return
end
before = balances[account]
Thread.pass
after = before + delta
balances[account] = after
ticket.release
action, sign = delta < 0 ? ["withdraw", "-"] : ["deposit", "+"]
log.info("account #{account} #{action} #{sign}$#{AMOUNT} -> $#{after}")
endपूरा उदाहरण test_example.rb, test_bank_example.rb, test_bench.rb में देखें।