Skip to content

Instantly share code, notes, and snippets.

@chischaschos
Created November 1, 2011 23:09
Show Gist options
  • Save chischaschos/1332238 to your computer and use it in GitHub Desktop.
Save chischaschos/1332238 to your computer and use it in GitHub Desktop.
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)
@chischaschos
Copy link
Author

I don't like the fact that "items" gets negative values

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment