diff --git a/lib/govuk_app_config/govuk_healthcheck/redis.rb b/lib/govuk_app_config/govuk_healthcheck/redis.rb index b837a844..f8b2006a 100644 --- a/lib/govuk_app_config/govuk_healthcheck/redis.rb +++ b/lib/govuk_app_config/govuk_healthcheck/redis.rb @@ -1,3 +1,5 @@ +require "securerandom" + module GovukHealthcheck class Redis def name @@ -7,9 +9,11 @@ def name def status client = ::Redis.new - client.set("healthcheck", "val") - client.get("healthcheck") - client.del("healthcheck") + key = "healthcheck-#{SecureRandom.hex}" + + client.set(key, "val") + client.get(key) + client.del(key) client.close diff --git a/spec/lib/govuk_healthcheck/redis_spec.rb b/spec/lib/govuk_healthcheck/redis_spec.rb index b94c74b8..0e699133 100644 --- a/spec/lib/govuk_healthcheck/redis_spec.rb +++ b/spec/lib/govuk_healthcheck/redis_spec.rb @@ -9,12 +9,13 @@ before do stub_const("Redis", redis) allow(redis).to receive(:new).and_return(redis_client) + allow(SecureRandom).to receive(:hex).and_return("abc") end context "when the database is connected" do before do allow(redis_client) - .to receive(:set).with("healthcheck", anything) + .to receive(:set).with("healthcheck-abc", anything) end it_behaves_like "a healthcheck" @@ -27,7 +28,7 @@ context "when the database is not connected" do before do allow(redis_client) - .to receive(:set).with("healthcheck", anything) + .to receive(:set).with("healthcheck-abc", anything) .and_raise("error") end