Module: Swagger::Commands::Strings
- Included in:
- Redis
- Defined in:
- lib/swagger/commands/strings.rb
Instance Method Summary collapse
- #decr(key) ⇒ Object
- #decrby(key, value) ⇒ Object
- #get(key) ⇒ Object
- #incr(key) ⇒ Object
- #incrby(key, value) ⇒ Object
- #mapped_mget(*keys) ⇒ Object
- #mget(*keys) ⇒ Object
- #set(key, value) ⇒ Object
- #setnx(key, value) ⇒ Object
Instance Method Details
#decr(key) ⇒ Object
30 31 32 |
# File 'lib/swagger/commands/strings.rb', line 30 def decr(key) decrby(key, '1') end |
#decrby(key, value) ⇒ Object
41 42 43 44 45 46 |
# File 'lib/swagger/commands/strings.rb', line 41 def decrby(key, value) object = ResqueValue.find_or_initialize_by_key(key.to_s) object.value = (object.value.to_i - value.to_i).to_s object.save! object.value end |
#get(key) ⇒ Object
5 6 7 8 |
# File 'lib/swagger/commands/strings.rb', line 5 def get(key) resque_value = ResqueValue.first(:conditions => {:key => key}) resque_value.value if resque_value end |
#incr(key) ⇒ Object
26 27 28 |
# File 'lib/swagger/commands/strings.rb', line 26 def incr(key) incrby(key, '1') end |
#incrby(key, value) ⇒ Object
34 35 36 37 38 39 |
# File 'lib/swagger/commands/strings.rb', line 34 def incrby(key, value) object = ResqueValue.find_or_initialize_by_key(key.to_s) object.value = (object.value.to_i + value.to_i).to_s object.save! object.value end |
#mapped_mget(*keys) ⇒ Object
48 49 50 |
# File 'lib/swagger/commands/strings.rb', line 48 def mapped_mget(*keys) Hash[*keys.zip(mget(*keys)).flatten] end |
#mget(*keys) ⇒ Object
52 53 54 55 56 |
# File 'lib/swagger/commands/strings.rb', line 52 def mget(*keys) keys.collect!{|key| key.to_s } resque_values = ResqueValue.all(:conditions => {:key => keys}) resque_values.map(&:value) end |
#set(key, value) ⇒ Object
10 11 12 13 14 15 |
# File 'lib/swagger/commands/strings.rb', line 10 def set(key, value) resque_value = ResqueValue.find_or_initialize_by_key(key.to_s) resque_value.value = value resque_value.save! value end |
#setnx(key, value) ⇒ Object
17 18 19 20 21 22 23 24 |
# File 'lib/swagger/commands/strings.rb', line 17 def setnx(key, value) resque_value = ResqueValue.find_or_initialize_by_key(key.to_s) if resque_value.new_record? resque_value.value = value resque_value.save! end resque_value.value end |