Class: Bloomrb
- Inherits:
-
Object
- Object
- Bloomrb
- Defined in:
- lib/bloomrb.rb
Instance Attribute Summary collapse
-
#host ⇒ Object
Returns the value of attribute host.
-
#port ⇒ Object
Returns the value of attribute port.
-
#retries ⇒ Object
Returns the value of attribute retries.
Instance Method Summary collapse
- #all?(filter, keys) ⇒ Boolean
- #any?(filter, keys) ⇒ Boolean
- #bulk(filter, keys) ⇒ Object
- #check(filter, key) ⇒ Object
- #clear(filter) ⇒ Object
- #close(filter) ⇒ Object
- #create(filter, opts = {}) ⇒ Object
- #disconnect ⇒ Object
- #drop(filter) ⇒ Object
- #filter(name) ⇒ Object
- #flush(filter = nil) ⇒ Object
- #info(filter) ⇒ Object
-
#initialize(host = 'localhost', port = 8673, retries = 5) ⇒ Bloomrb
constructor
A new instance of Bloomrb.
- #list ⇒ Object
- #multi(filter, keys) ⇒ Object
- #set(filter, key) ⇒ Object
- #socket ⇒ Object
Constructor Details
permalink #initialize(host = 'localhost', port = 8673, retries = 5) ⇒ Bloomrb
Returns a new instance of Bloomrb.
6 7 8 9 10 |
# File 'lib/bloomrb.rb', line 6 def initialize(host = 'localhost', port = 8673, retries = 5) self.host = host self.port = port self.retries = retries end |
Instance Attribute Details
permalink #host ⇒ Object
Returns the value of attribute host.
4 5 6 |
# File 'lib/bloomrb.rb', line 4 def host @host end |
permalink #port ⇒ Object
Returns the value of attribute port.
4 5 6 |
# File 'lib/bloomrb.rb', line 4 def port @port end |
permalink #retries ⇒ Object
Returns the value of attribute retries.
4 5 6 |
# File 'lib/bloomrb.rb', line 4 def retries @retries end |
Instance Method Details
permalink #all?(filter, keys) ⇒ Boolean
68 69 70 71 72 |
# File 'lib/bloomrb.rb', line 68 def all?(filter, keys) return true if keys.empty? !!(execute('m', filter, *keys) !~ /No/) end |
permalink #any?(filter, keys) ⇒ Boolean
62 63 64 65 66 |
# File 'lib/bloomrb.rb', line 62 def any?(filter, keys) return false if keys.empty? !!(execute('m', filter, *keys) =~ /Yes/) end |
permalink #bulk(filter, keys) ⇒ Object
[View source]
78 79 80 81 82 |
# File 'lib/bloomrb.rb', line 78 def bulk(filter, keys) return "" if keys.empty? execute('b', filter, *keys) end |
permalink #check(filter, key) ⇒ Object
[View source]
52 53 54 |
# File 'lib/bloomrb.rb', line 52 def check(filter, key) execute('c', filter, key) == 'Yes' end |
permalink #clear(filter) ⇒ Object
[View source]
48 49 50 |
# File 'lib/bloomrb.rb', line 48 def clear(filter) execute('clear', filter) == 'Done' end |
permalink #close(filter) ⇒ Object
[View source]
44 45 46 |
# File 'lib/bloomrb.rb', line 44 def close(filter) execute('close', filter) == 'Done' end |
permalink #create(filter, opts = {}) ⇒ Object
[View source]
25 26 27 |
# File 'lib/bloomrb.rb', line 25 def create(filter, opts = {}) execute('create', filter, opts) == 'Done' end |
permalink #disconnect ⇒ Object
[View source]
16 17 18 19 |
# File 'lib/bloomrb.rb', line 16 def disconnect @socket.close if @socket @socket = nil end |
permalink #drop(filter) ⇒ Object
[View source]
40 41 42 |
# File 'lib/bloomrb.rb', line 40 def drop(filter) execute('drop', filter) == 'Done' end |
permalink #filter(name) ⇒ Object
[View source]
21 22 23 |
# File 'lib/bloomrb.rb', line 21 def filter(name) BloomFilter.new(name, self) end |
permalink #flush(filter = nil) ⇒ Object
[View source]
88 89 90 |
# File 'lib/bloomrb.rb', line 88 def flush(filter = nil) execute('flush', filter) == 'Done' end |
permalink #info(filter) ⇒ Object
[View source]
84 85 86 |
# File 'lib/bloomrb.rb', line 84 def info(filter) Hash[execute('info', filter).map{|s| s.split(' ')}] end |
permalink #list ⇒ Object
[View source]
29 30 31 32 33 34 35 36 37 38 |
# File 'lib/bloomrb.rb', line 29 def list execute('list').map do |line| name, probability, size, capacity, items = line.split(' ') {:name => name, :probability => probability.to_f, :size => size.to_i, :capacity => capacity.to_i, :items => items.to_i} end end |
permalink #multi(filter, keys) ⇒ Object
[View source]
56 57 58 59 60 |
# File 'lib/bloomrb.rb', line 56 def multi(filter, keys) return Hash.new if keys.empty? Hash[keys.zip(execute('m', filter, *keys).split(' ').map{|r| r == 'Yes'})] end |
permalink #set(filter, key) ⇒ Object
[View source]
74 75 76 |
# File 'lib/bloomrb.rb', line 74 def set(filter, key) execute('s', filter, key) == 'Yes' end |
permalink #socket ⇒ Object
[View source]
12 13 14 |
# File 'lib/bloomrb.rb', line 12 def socket @socket ||= TCPSocket.new(host, port) end |