Created
November 1, 2011 23:09
-
-
Save chischaschos/1332238 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'rubygems' | |
require 'redis' | |
redis = Redis.new | |
redis.set 'items', 10 | |
threads = [] | |
ARGV[0].to_i.times do |time| | |
threads << Thread.new(time) do |time| | |
redis = Redis.new | |
items = redis.decr('items').to_i | |
if items > 0 | |
p "##{time} bought! #{items}" | |
elsif items < 0 | |
p redis.incr 'items' | |
end | |
end | |
end | |
threads.each(&:join) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I don't like the fact that "items" gets negative values