Class: Alchemy
- Inherits:
-
Memcached
- Object
- Memcached
- Alchemy
- Defined in:
- lib/alchemy.rb
Instance Method Summary collapse
- #add(key, value, timeout = 0) ⇒ Object
-
#get(keys) ⇒ Object
GETTER.
- #replace(key, value, timeout = 0) ⇒ Object
-
#set(key, value, timeout = 0) ⇒ Object
SETTERS.
Instance Method Details
#add(key, value, timeout = 0) ⇒ Object
12 13 14 15 16 |
# File 'lib/alchemy.rb', line 12 def add(key, value, timeout=0) check_return_code( Lib.memcached_add(@struct, key, value.to_s, timeout, FLAGS) ) end |
#get(keys) ⇒ Object
GETTER
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/alchemy.rb', line 25 def get(keys)#, marshal=true) if keys.is_a? Array # Multi get keys.map! { |key| key } hash = {} ret = Lib.memcached_mget(@struct, keys); check_return_code(ret) keys.size.times do value, key, flags, ret = Lib.memcached_fetch_rvalue(@struct) break if ret == Lib::MEMCACHED_END check_return_code(ret) hash[key] = JSON.parse(value) end hash else # Single get value, flags, ret = Lib.memcached_get_rvalue(@struct, keys) #check_return_code(ret) unless value.empty? value = JSON.parse(value) else value = nil end value end end |
#replace(key, value, timeout = 0) ⇒ Object
18 19 20 21 22 |
# File 'lib/alchemy.rb', line 18 def replace(key, value, timeout=0) check_return_code( Lib.memcached_replace(@struct, key, value.to_a.to_json, timeout, FLAGS) ) end |
#set(key, value, timeout = 0) ⇒ Object
SETTERS
6 7 8 9 10 |
# File 'lib/alchemy.rb', line 6 def set(key, value, timeout=0) check_return_code( Lib.memcached_set(@struct, key, value.to_s, timeout, FLAGS) ) end |