Skip to content

Commit

Permalink
Simplify the with/without verbage
Browse files Browse the repository at this point in the history
  • Loading branch information
evanphx committed May 17, 2012
1 parent 6c38a95 commit e06ec87
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 6 deletions.
10 changes: 7 additions & 3 deletions lib/redis/client.rb
Expand Up @@ -110,7 +110,7 @@ def call_loop(command)
end

def call_pipeline(pipeline)
without_reconnect pipeline.without_reconnect? do
with_reconnect pipeline.with_reconnect? do
if pipeline.shutdown?
begin
pipeline.finish(call_pipelined(pipeline.commands))
Expand Down Expand Up @@ -226,15 +226,19 @@ def without_socket_timeout
end
end

def without_reconnect(val=true)
def with_reconnect(val=true)
begin
original, @reconnect = @reconnect, !val
original, @reconnect = @reconnect, val
yield
ensure
@reconnect = original
end
end

def without_reconnect(val=true, &blk)
with_reconnect(!val, &blk)
end

protected

def logging(commands)
Expand Down
15 changes: 12 additions & 3 deletions lib/redis/pipeline.rb
Expand Up @@ -9,13 +9,17 @@ class Pipeline
attr :futures

def initialize
@without_reconnect = false
@with_reconnect = true
@shutdown = false
@futures = []
end

def with_reconnect?
@with_reconnect
end

def without_reconnect?
@without_reconnect
!@with_reconnect
end

def shutdown?
Expand All @@ -41,8 +45,13 @@ def commands
@futures.map { |f| f._command }
end

def with_reconnect(&block)
@with_reconnect = true
yield
end

def without_reconnect(&block)
@without_reconnect = true
@with_reconnect = false
yield
end

Expand Down

0 comments on commit e06ec87

Please sign in to comment.