Permalink
Browse files

add increment/decrement and some error handling

  • Loading branch information...
1 parent 0121e81 commit 25b927a6526b8c2ed56da35a2e5059e552bf52b4 @pedro committed Mar 26, 2012
Showing with 24 additions and 0 deletions.
  1. +24 −0 lib/redis-store-rails2.rb
@@ -15,12 +15,36 @@ def initialize(address=nil)
def read(key, options = nil) # :nodoc:
super
@store.get(key)
+ rescue Errno::ECONNREFUSED => e
+ logger.error("RedisStoreRails2 error (#{e}): #{e.message}")
+ nil
end
def write(key, value, options={})
super
response = @store.set(key, value)
@store.expire(key, options[:expires_in]) if options[:expires_in]
response == "OK"
+ rescue Errno::ECONNREFUSED => e
+ logger.error("RedisStoreRails2 error (#{e}): #{e.message}")
+ false
+ end
+
+ def delete(key, options={})
+ super
+ response = @store.del(key)
+ response >= 0
+ end
+
+ def increment(key, amount = 1)
+ @store.incrby key, amount
+ end
+
+ def decrement(key, amount = 1)
+ @data.decrby key, amount
+ end
+
+ def clear
+ @store.flushdb
end
end

0 comments on commit 25b927a

Please sign in to comment.