lib/redis.rb in redis-2.0.0.rc1 vs lib/redis.rb in redis-2.0.0.rc2
- old
+ new
@@ -1,9 +1,9 @@
require 'socket'
class Redis
- VERSION = "2.0.0.rc1"
+ VERSION = "2.0.0.rc2"
class ProtocolError < RuntimeError
def initialize(reply_type)
super("Protocol error, got '#{reply_type}' as initial reply byte")
end
@@ -144,15 +144,15 @@
def rpop(key)
@client.call(:rpop, key)
end
def blpop(key, timeout)
- @client.call_blocking(:blpop, key, timeout)
+ @client.call_without_timeout(:blpop, key, timeout)
end
def brpop(key, timeout)
- @client.call_blocking(:brpop, key, timeout)
+ @client.call_without_timeout(:brpop, key, timeout)
end
def rpoplpush(source, destination)
@client.call(:rpoplpush, source, destination)
end
@@ -428,51 +428,54 @@
def publish(channel, message)
@client.call(:publish, channel, message)
end
+ def subscribed?
+ @client.kind_of? SubscribedClient
+ end
+
def unsubscribe(*channels)
- if @client.kind_of?(SubscribedClient)
- @client = @client.unsubscribe(*channels)
- else
- @client.call(:unsubscribe, *channels)
- end
+ raise RuntimeError, "Can't unsubscribe if not subscribed." unless subscribed?
+ @client.unsubscribe(*channels)
end
+ def punsubscribe(*channels)
+ raise RuntimeError, "Can't unsubscribe if not subscribed." unless subscribed?
+ @client.punsubscribe(*channels)
+ end
+
def subscribe(*channels, &block)
- if @client.kind_of?(SubscribedClient)
- @client.call(:subscribe, *channels)
- else
- begin
- original, @client = @client, SubscribedClient.new(@client)
- @client.subscribe(*channels, &block)
- ensure
- @client = original
- end
- end
+ subscription(:subscribe, channels, block)
end
def psubscribe(*channels, &block)
- if @client.kind_of?(SubscribedClient)
- @client.call(:psubscribe, *channels)
- else
- begin
- original, @client = @client, SubscribedClient.new(@client)
- @client.psubscribe(*channels, &block)
- ensure
- @client = original
- end
- end
+ subscription(:psubscribe, channels, block)
end
+ def id
+ @client.id
+ end
+
def method_missing(command, *args)
@client.call(command, *args)
end
private
def _bool(value)
value == 1
+ end
+
+ def subscription(method, channels, block)
+ return @client.call(method, *channels) if subscribed?
+
+ begin
+ original, @client = @client, SubscribedClient.new(@client)
+ @client.send(method, *channels, &block)
+ ensure
+ @client = original
+ end
end
end
begin