Skip to content

Commit

Permalink
Merge pull request #792 from petergoldstein/bugfix/766
Browse files Browse the repository at this point in the history
Restore `with` method for compatibility with existing Rails code
  • Loading branch information
petergoldstein authored Oct 13, 2021
2 parents 9761ca4 + ff8b2d9 commit a48f759
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
5 changes: 5 additions & 0 deletions lib/dalli/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,11 @@ def close
end
alias_method :reset, :close

# Stub method so a bare Dalli client can pretend to be a connection pool.
def with
yield self
end

private

def cas_core(key, always_set, ttl = nil, options = nil)
Expand Down
9 changes: 9 additions & 0 deletions test/test_dalli.rb
Original file line number Diff line number Diff line change
Expand Up @@ -742,5 +742,14 @@
end
end

it "supports the with method" do
memcached_persistent do |dc|
dc.with { |c| c.set("some_key", "some_value") }
assert_equal "some_value", dc.get("some_key")

dc.with { |c| c.delete("some_key") }
assert_nil dc.get("some_key")
end
end
end
end

0 comments on commit a48f759

Please sign in to comment.