lib/ffi/hiredis_vip/client.rb in ffi-hiredis_vip-0.1.0.pre1 vs lib/ffi/hiredis_vip/client.rb in ffi-hiredis_vip-0.1.0.pre2
- old
+ new
@@ -48,14 +48,18 @@
def synchronize
mon_synchronize { yield(@connection) }
end
+ def execute_command(*args)
+ ::FFI::HiredisVip::Core.command(*args)
+ end
+
def dbsize
reply = nil
synchronize do |connection|
- reply = ::FFI::HiredisVip::Core.command(connection, "DBSIZE")
+ reply = execute_command(connection, "DBSIZE")
end
case reply[:type]
when :REDIS_REPLY_INTEGER
reply[:integer]
@@ -67,11 +71,11 @@
def decr(key)
reply = nil
command = "DECR %b"
command_args = [ :string, key, :size_t, key.size ]
synchronize do |connection|
- reply = ::FFI::HiredisVip::Core.command(connection, command, *command_args)
+ reply = execute_command(connection, command, *command_args)
end
return nil if reply.nil? || reply.null?
case reply[:type]
@@ -86,11 +90,11 @@
reply = nil
_amount = "#{amount}"
command = "DECRBY %b %b"
command_args = [ :string, key, :size_t, key.size, :string, _amount, :size_t, _amount.size ]
synchronize do |connection|
- reply = ::FFI::HiredisVip::Core.command(connection, command, *command_args)
+ reply = execute_command(connection, command, *command_args)
end
return nil if reply.nil? || reply.null?
case reply[:type]
@@ -110,11 +114,11 @@
keys.each do |key|
command_args << :string << key << :size_t << key.size
end
synchronize do |connection|
- reply = ::FFI::HiredisVip::Core.command(connection, command, *command_args)
+ reply = execute_command(connection, command, *command_args)
end
return nil if reply.nil? || reply.null?
case reply[:type]
@@ -128,11 +132,11 @@
def dump(key)
reply = nil
command = "DUMP %b"
command_args = [ :string, key, :size_t, key.size ]
synchronize do |connection|
- reply = ::FFI::HiredisVip::Core.command(connection, command, *command_args)
+ reply = execute_command(connection, command, *command_args)
end
return nil if reply.nil? || reply.null?
case reply[:type]
@@ -146,11 +150,11 @@
def echo(value)
reply = nil
command = "ECHO %b"
command_args = [ :string, value, :size_t, value.size ]
synchronize do |connection|
- reply = ::FFI::HiredisVip::Core.command(connection, command, *command_args)
+ reply = execute_command(connection, command, *command_args)
end
return nil if reply.nil? || reply.null?
case reply[:type]
@@ -179,11 +183,11 @@
reply = nil
time_in_seconds = "#{seconds}"
command = "EXPIRE %b %b"
command_args = [ :string, key, :size_t, key.size, :string, time_in_seconds, :size_t, time_in_seconds.size ]
synchronize do |connection|
- reply = ::FFI::HiredisVip::Core.command(connection, command, *command_args)
+ reply = execute_command(connection, command, *command_args)
end
# TODO: should we return a 0 here?
return 0 if reply.nil? || reply.null?
@@ -203,11 +207,11 @@
reply = nil
epoch = "#{unix_time}"
command = "EXPIREAT %b %b"
command_args = [ :string, key, :size_t, key.size, :string, epoch, :size_t, epoch.size ]
synchronize do |connection|
- reply = ::FFI::HiredisVip::Core.command(connection, command, *command_args)
+ reply = execute_command(connection, command, *command_args)
end
return 0 if reply.nil? || reply.null?
case reply[:type]
@@ -223,11 +227,11 @@
end
def flushall
reply = nil
synchronize do |connection|
- reply = ::FFI::HiredisVip::Core.command(connection, "FLUSHALL")
+ reply = execute_command(connection, "FLUSHALL")
end
return "" if reply.nil? || reply.null?
case reply[:type]
@@ -243,11 +247,11 @@
end
def flushdb
reply = nil
synchronize do |connection|
- reply = ::FFI::HiredisVip::Core.command(connection, "FLUSHDB")
+ reply = execute_command(connection, "FLUSHDB")
end
return "" if reply.nil? || reply.null?
case reply[:type]
@@ -266,11 +270,11 @@
reply = nil
command = "GET %b"
command_args = [ :string, key, :size_t, key.size ]
synchronize do |connection|
- reply = ::FFI::HiredisVip::Core.command(connection, command, *command_args)
+ reply = execute_command(connection, command, *command_args)
end
return nil if reply.nil? || reply.null?
case reply[:type]
@@ -287,11 +291,11 @@
def incr(key)
reply = nil
command = "INCR %b"
command_args = [ :string, key, :size_t, key.size ]
synchronize do |connection|
- reply = ::FFI::HiredisVip::Core.command(connection, command, *command_args)
+ reply = execute_command(connection, command, *command_args)
end
return nil if reply.nil? || reply.null?
case reply[:type]
@@ -306,11 +310,11 @@
reply = nil
_amount = "#{amount}"
command = "INCRBY %b %b"
command_args = [ :string, key, :size_t, key.size, :string, _amount, :size_t, _amount.size ]
synchronize do |connection|
- reply = ::FFI::HiredisVip::Core.command(connection, command, *command_args)
+ reply = execute_command(connection, command, *command_args)
end
return nil if reply.nil? || reply.null?
case reply[:type]
@@ -322,11 +326,11 @@
end
def info
reply = nil
synchronize do |connection|
- reply = ::FFI::HiredisVip::Core.command(connection, "INFO")
+ reply = execute_command(connection, "INFO")
end
return "" if reply.nil? || reply.null?
case reply[:type]
@@ -356,11 +360,11 @@
end
def ping
reply = nil
synchronize do |connection|
- reply = ::FFI::HiredisVip::Core.command(connection, "PING")
+ reply = execute_command(connection, "PING")
end
return nil if reply.nil? || reply.null?
case reply[:type]
@@ -433,11 +437,11 @@
reply = nil
db = "#{db}"
command = "SELECT %b"
command_args = [ :string, db, :size_t, db.size ]
synchronize do |connection|
- reply = ::FFI::HiredisVip::Core.command(connection, command, *command_args)
+ reply = execute_command(connection, command, *command_args)
end
return nil if reply.nil? || reply.null?
case reply[:type]
@@ -496,10 +500,10 @@
def ttl(key)
reply = nil
command = "TTL %b"
command_args = [ :string, key, :size_t, key.size ]
synchronize do |connection|
- reply = ::FFI::HiredisVip::Core.command(connection, command, *command_args)
+ reply = execute_command(connection, command, *command_args)
end
return nil if reply.nil? || reply.null?
case reply[:type]