mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Redis cache store: fail gracefully when max clients reached
This commit is contained in:
parent
4c785f7360
commit
6229c2b223
2 changed files with 23 additions and 2 deletions
|
@ -476,7 +476,7 @@ module ActiveSupport
|
|||
|
||||
def failsafe(method, returning: nil)
|
||||
yield
|
||||
rescue ::Redis::BaseConnectionError => e
|
||||
rescue ::Redis::BaseError => e
|
||||
handle_exception exception: e, method: method, returning: returning
|
||||
returning
|
||||
end
|
||||
|
|
|
@ -233,7 +233,13 @@ module ActiveSupport::Cache::RedisCacheStoreTests
|
|||
end
|
||||
end
|
||||
|
||||
class FailureSafetyTest < StoreTest
|
||||
class MaxClientsReachedRedisClient < Redis::Client
|
||||
def ensure_connected
|
||||
raise Redis::CommandError
|
||||
end
|
||||
end
|
||||
|
||||
class FailureSafetyFromUnavailableClientTest < StoreTest
|
||||
include FailureSafetyBehavior
|
||||
|
||||
private
|
||||
|
@ -248,6 +254,21 @@ module ActiveSupport::Cache::RedisCacheStoreTests
|
|||
end
|
||||
end
|
||||
|
||||
class FailureSafetyFromMaxClientsReachedErrorTest < StoreTest
|
||||
include FailureSafetyBehavior
|
||||
|
||||
private
|
||||
def emulating_unavailability
|
||||
old_client = Redis.send(:remove_const, :Client)
|
||||
Redis.const_set(:Client, MaxClientsReachedRedisClient)
|
||||
|
||||
yield ActiveSupport::Cache::RedisCacheStore.new
|
||||
ensure
|
||||
Redis.send(:remove_const, :Client)
|
||||
Redis.const_set(:Client, old_client)
|
||||
end
|
||||
end
|
||||
|
||||
class DeleteMatchedTest < StoreTest
|
||||
test "deletes keys matching glob" do
|
||||
@cache.write("foo", "bar")
|
||||
|
|
Loading…
Reference in a new issue