Class: MemcacheCheck::Server
- Inherits:
-
Object
- Object
- MemcacheCheck::Server
- Defined in:
- lib/memcache_check/server.rb
Instance Attribute Summary collapse
-
#fails ⇒ Object
readonly
Returns the value of attribute fails.
-
#hostname ⇒ Object
readonly
Returns the value of attribute hostname.
-
#passes ⇒ Object
readonly
Returns the value of attribute passes.
-
#port ⇒ Object
readonly
Returns the value of attribute port.
-
#time ⇒ Object
readonly
Returns the value of attribute time.
Instance Method Summary collapse
- #benchmark(num_times) ⇒ Object
- #get(key) ⇒ Object
-
#initialize(hostname = '127.0.0.1', port = '11211') ⇒ Server
constructor
A new instance of Server.
- #is_valid?(key, value) ⇒ Boolean
- #run_test ⇒ Object
- #set(key, value) ⇒ Object
- #test_run ⇒ Object
Constructor Details
#initialize(hostname = '127.0.0.1', port = '11211') ⇒ Server
Returns a new instance of Server.
8 9 10 11 12 13 14 |
# File 'lib/memcache_check/server.rb', line 8 def initialize(hostname = '127.0.0.1', port = '11211') @memcache_client = Dalli::Client.new("#{hostname}:#{port}") @hostname = hostname @port = port @passes = 0 @fails = 0 end |
Instance Attribute Details
#fails ⇒ Object (readonly)
Returns the value of attribute fails.
6 7 8 |
# File 'lib/memcache_check/server.rb', line 6 def fails @fails end |
#hostname ⇒ Object (readonly)
Returns the value of attribute hostname.
6 7 8 |
# File 'lib/memcache_check/server.rb', line 6 def hostname @hostname end |
#passes ⇒ Object (readonly)
Returns the value of attribute passes.
6 7 8 |
# File 'lib/memcache_check/server.rb', line 6 def passes @passes end |
#port ⇒ Object (readonly)
Returns the value of attribute port.
6 7 8 |
# File 'lib/memcache_check/server.rb', line 6 def port @port end |
#time ⇒ Object (readonly)
Returns the value of attribute time.
6 7 8 |
# File 'lib/memcache_check/server.rb', line 6 def time @time end |
Instance Method Details
#benchmark(num_times) ⇒ Object
16 17 18 19 20 21 22 23 |
# File 'lib/memcache_check/server.rb', line 16 def benchmark(num_times) test_run @time = Benchmark.measure do num_times.times do run_test end end end |
#get(key) ⇒ Object
52 53 54 |
# File 'lib/memcache_check/server.rb', line 52 def get(key) @memcache_client.get(key) end |
#is_valid?(key, value) ⇒ Boolean
56 57 58 |
# File 'lib/memcache_check/server.rb', line 56 def is_valid?(key, value) value == get(key) end |
#run_test ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/memcache_check/server.rb', line 25 def run_test key, value = Utils.generate_key_value_pair begin set(key, value) if is_valid?(key, value) @passes += 1 else @fails += 1 end rescue @fails += 1 end end |
#set(key, value) ⇒ Object
48 49 50 |
# File 'lib/memcache_check/server.rb', line 48 def set(key, value) @memcache_client.set(key, value) end |
#test_run ⇒ Object
39 40 41 42 43 44 45 46 |
# File 'lib/memcache_check/server.rb', line 39 def test_run key, value = Utils.generate_key_value_pair begin set(key, value) get(key) rescue end end |