The store encapsulates the communication with the redis key-value store. To the outside it looks like normal module methods would be called. It allows the simple starting of a test on multiple bots with the latest test reciept.
Add a tracking to the trackings
# File lib/bigbench/store.rb, line 77 def self.add_tracking(tracking) @redis.rpush(TRACKINGS_KEY, tracking) end
Adds a bot to the currently working bots list
# File lib/bigbench/store.rb, line 62 def self.bot_is_working(id) @redis.sadd(BOTS_KEY, id) end
Removes a bot to the currently working bots list
# File lib/bigbench/store.rb, line 67 def self.bot_stopped_working(id) @redis.srem(BOTS_KEY, id) end
Shows all currently working bots
# File lib/bigbench/store.rb, line 72 def self.bots @redis.smembers(BOTS_KEY) end
How many trackings are in the list
# File lib/bigbench/store.rb, line 87 def self.count_trackings @redis.llen(TRACKINGS_KEY) end
Pop a tracking from the beginning of the list
# File lib/bigbench/store.rb, line 82 def self.pop_tracking @redis.lpop(TRACKINGS_KEY) end
Deletes all BigBench related keys on the redis store
# File lib/bigbench/store.rb, line 23 def self.reset! return if @redis.nil? @redis.del(TEST_RECEIPT_KEY) @redis.del(RUNNING_KEY) @redis.del(BOTS_KEY) @redis.del(TRACKINGS_KEY) end
Returns true if a bot test has been started
# File lib/bigbench/store.rb, line 57 def self.running? @redis.get(RUNNING_KEY) == "1" end
Setup the redis storage. Default values are localhost:6379
and
no password. This needs to be called for any bot test
# File lib/bigbench/store.rb, line 16 def self.setup!(url = "localhost:6379", password = nil) uri = URI(url) @redis = ::Redis.new :host => uri.host, :port => uri.port, :password => password true end
Start the tests for all bots by setting the running key
# File lib/bigbench/store.rb, line 47 def self.start @redis.set(RUNNING_KEY, "1") end
Stops the test for all bots by unsetting the running key
# File lib/bigbench/store.rb, line 52 def self.stop @redis.set(RUNNING_KEY, "0") end
Gets the current test from the redis
# File lib/bigbench/store.rb, line 42 def self.test @redis.get(TEST_RECEIPT_KEY) end
Stores the current test receipt for all bots on the redis instance
# File lib/bigbench/store.rb, line 33 def self.test=(test) if test @redis.set(TEST_RECEIPT_KEY, test) else @redis.del(TEST_RECEIPT_KEY) end end