Class: Spymemcached
- Inherits:
-
Object
- Object
- Spymemcached
- Defined in:
- lib/spymemcached.rb
Instance Method Summary collapse
- #add(key, value, expiration = 0, marshal = true) ⇒ Object
- #append(key, value) ⇒ Object
- #decr(key, by = 1) ⇒ Object
- #del(key) ⇒ Object
- #flush ⇒ Object
- #get(key, marshal = true) ⇒ Object
- #incr(key, by = 1) ⇒ Object
-
#initialize(servers) ⇒ Spymemcached
constructor
A new instance of Spymemcached.
- #multiget(keys, marshal = true) ⇒ Object
- #prepend(key, value) ⇒ Object
- #set(key, value, expiration = 0, marshal = true) ⇒ Object
Constructor Details
#initialize(servers) ⇒ Spymemcached
Returns a new instance of Spymemcached.
8 9 10 11 12 13 |
# File 'lib/spymemcached.rb', line 8 def initialize(servers) @client = MemcachedClient.new(servers.map do |s| host, port = s.split(":") InetSocketAddress.new(host, port.to_i) end) end |
Instance Method Details
#add(key, value, expiration = 0, marshal = true) ⇒ Object
44 45 46 |
# File 'lib/spymemcached.rb', line 44 def add(key, value, expiration = 0, marshal = true) @client.add(key, expiration, marshal(value, marshal)).get end |
#append(key, value) ⇒ Object
32 33 34 |
# File 'lib/spymemcached.rb', line 32 def append(key, value) @client.append(0, key, value).get end |
#decr(key, by = 1) ⇒ Object
28 29 30 |
# File 'lib/spymemcached.rb', line 28 def decr(key, by = 1) @client.decr(key, by) end |
#del(key) ⇒ Object
48 49 50 |
# File 'lib/spymemcached.rb', line 48 def del(key) @client.delete(key).get end |
#flush ⇒ Object
52 53 54 |
# File 'lib/spymemcached.rb', line 52 def flush @client.flush end |
#get(key, marshal = true) ⇒ Object
19 20 21 22 |
# File 'lib/spymemcached.rb', line 19 def get(key, marshal = true) value = @client.get(key) marshal && value ? marshal_load(value) : value end |
#incr(key, by = 1) ⇒ Object
24 25 26 |
# File 'lib/spymemcached.rb', line 24 def incr(key, by = 1) @client.incr(key, by) end |
#multiget(keys, marshal = true) ⇒ Object
40 41 42 |
# File 'lib/spymemcached.rb', line 40 def multiget(keys, marshal = true) Hash[*@client.getBulk(*keys).map { |k,v| [k, marshal ? marshal_load(v) : v] }.flatten] end |
#prepend(key, value) ⇒ Object
36 37 38 |
# File 'lib/spymemcached.rb', line 36 def prepend(key, value) @client.prepend(0, key, value).get end |
#set(key, value, expiration = 0, marshal = true) ⇒ Object
15 16 17 |
# File 'lib/spymemcached.rb', line 15 def set(key, value, expiration = 0, marshal = true) @client.set(key, expiration, marshal(value, marshal)) end |