lib/ffi/hiredis_vip/client.rb in ffi-hiredis_vip-0.1.0.pre3 vs lib/ffi/hiredis_vip/client.rb in ffi-hiredis_vip-0.1.0.pre4

- old
+ new

@@ -64,10 +64,12 @@ when :REDIS_REPLY_INTEGER reply[:integer] else 0 end + ensure + ::FFI::HiredisVip::Core.freeReplyObject(reply.pointer) if reply end def decr(key) reply = nil command = "DECR %b" @@ -82,10 +84,12 @@ when :REDIS_REPLY_INTEGER reply[:integer] else 0 end + ensure + ::FFI::HiredisVip::Core.freeReplyObject(reply.pointer) if reply end def decrby(key, amount) reply = nil _amount = "#{amount}" @@ -101,10 +105,12 @@ when :REDIS_REPLY_INTEGER reply[:integer] else 0 end + ensure + ::FFI::HiredisVip::Core.freeReplyObject(reply.pointer) if reply end def del(*keys) reply = nil keys = keys.flatten @@ -125,10 +131,12 @@ when :REDIS_REPLY_INTEGER reply[:integer] else 0 end + ensure + ::FFI::HiredisVip::Core.freeReplyObject(reply.pointer) if reply end def dump(key) reply = nil command = "DUMP %b" @@ -139,14 +147,16 @@ return nil if reply.nil? || reply.null? case reply[:type] when :REDIS_REPLY_STRING - reply[:str] + reply[:str].dup else nil end + ensure + ::FFI::HiredisVip::Core.freeReplyObject(reply.pointer) if reply end def echo(value) reply = nil command = "ECHO %b" @@ -157,16 +167,18 @@ return nil if reply.nil? || reply.null? case reply[:type] when :REDIS_REPLY_STRING - reply[:str] + reply[:str].dup when :REDIS_REPLY_NIL nil else nil end + ensure + ::FFI::HiredisVip::Core.freeReplyObject(reply.pointer) if reply end def echo?(value) echo(value) == value end @@ -195,10 +207,12 @@ when :REDIS_REPLY_INTEGER reply[:integer] else 0 end + ensure + ::FFI::HiredisVip::Core.freeReplyObject(reply.pointer) if reply end def expire?(key, seconds) expire(key, seconds) == 1 end @@ -218,10 +232,12 @@ when :REDIS_REPLY_INTEGER reply[:integer] else 0 end + ensure + ::FFI::HiredisVip::Core.freeReplyObject(reply.pointer) if reply end def expireat?(key, unix_time) expireat(key, unix_time) == 1 end @@ -234,14 +250,16 @@ return "" if reply.nil? || reply.null? case reply[:type] when :REDIS_REPLY_STRING - reply[:str] + reply[:str].dup else "" end + ensure + ::FFI::HiredisVip::Core.freeReplyObject(reply.pointer) if reply end def flushall? flushall == OK end @@ -254,14 +272,16 @@ return "" if reply.nil? || reply.null? case reply[:type] when :REDIS_REPLY_STRING - reply[:str] + reply[:str].dup else "" end + ensure + ::FFI::HiredisVip::Core.freeReplyObject(reply.pointer) if reply end def flushdb? flushdb == OK end @@ -277,16 +297,18 @@ return nil if reply.nil? || reply.null? case reply[:type] when :REDIS_REPLY_STRING - reply[:str] + reply[:str].dup when :REDIS_REPLY_NIL nil else nil # TODO: should this be empty string? end + ensure + ::FFI::HiredisVip::Core.freeReplyObject(reply.pointer) if reply end alias_method :[], :get def incr(key) reply = nil @@ -302,10 +324,12 @@ when :REDIS_REPLY_INTEGER reply[:integer] else 0 end + ensure + ::FFI::HiredisVip::Core.freeReplyObject(reply.pointer) if reply end def incrby(key, amount) reply = nil _amount = "#{amount}" @@ -321,10 +345,12 @@ when :REDIS_REPLY_INTEGER reply[:integer] else 0 end + ensure + ::FFI::HiredisVip::Core.freeReplyObject(reply.pointer) if reply end def info reply = nil synchronize do |connection| @@ -333,14 +359,16 @@ return "" if reply.nil? || reply.null? case reply[:type] when :REDIS_REPLY_STRING - reply[:str] + reply[:str].dup else "" end + ensure + ::FFI::HiredisVip::Core.freeReplyObject(reply.pointer) if reply end def keys(pattern) @keys_provider ||= ::FFI::HiredisVip::Keys.new(self) @keys_provider.keys(pattern) @@ -367,16 +395,18 @@ return nil if reply.nil? || reply.null? case reply[:type] when :REDIS_REPLY_STATUS - reply[:str] + reply[:str].dup when :REDIS_REPLY_STRING - reply[:str] + reply[:str].dup else "" end + ensure + ::FFI::HiredisVip::Core.freeReplyObject(reply.pointer) if reply end def ping? ping == PONG end @@ -395,10 +425,12 @@ when :REDIS_OK true else false end + ensure + ::FFI::HiredisVip::Core.freeReplyObject(reply.pointer) if reply end def sadd(key, *values) @sadd_provider.sadd(key, *values) end @@ -444,14 +476,16 @@ return nil if reply.nil? || reply.null? case reply[:type] when :REDIS_REPLY_STATUS - reply[:str] + reply[:str].dup else nil end + ensure + ::FFI::HiredisVip::Core.freeReplyObject(reply.pointer) if reply end def select?(db) select(db) == OK end @@ -509,9 +543,11 @@ case reply[:type] when :REDIS_REPLY_INTEGER reply[:integer] end + ensure + ::FFI::HiredisVip::Core.freeReplyObject(reply.pointer) if reply end def touch(*keys) @touch_provider.touch(*keys) end