From dd8e87e6264cca0205fe24c178b9d335ab2b5fb9 Mon Sep 17 00:00:00 2001 From: Konrad Date: Mon, 12 Sep 2022 13:18:38 +0200 Subject: [PATCH 1/2] Add support for redis-client, which does not automatically cast types to strings --- lib/split/alternative.rb | 2 +- lib/split/experiment.rb | 6 +++--- spec/experiment_spec.rb | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/split/alternative.rb b/lib/split/alternative.rb index 3d416188..1ba0ebff 100644 --- a/lib/split/alternative.rb +++ b/lib/split/alternative.rb @@ -166,7 +166,7 @@ def validate! end def reset - Split.redis.hmset key, "participant_count", 0, "completed_count", 0, "recorded_info", nil + Split.redis.hmset key, "participant_count", 0, "completed_count", 0, "recorded_info", nil.to_s unless goals.empty? goals.each do |g| field = "completed_count:#{g}" diff --git a/lib/split/experiment.rb b/lib/split/experiment.rb index ec78fae1..26c1792f 100644 --- a/lib/split/experiment.rb +++ b/lib/split/experiment.rb @@ -85,7 +85,7 @@ def save persist_experiment_configuration end - redis.hmset(experiment_config_key, :resettable, resettable, + redis.hmset(experiment_config_key, :resettable, resettable.to_s, :algorithm, algorithm.to_s) self end @@ -408,12 +408,12 @@ def cohorting_disabled? def disable_cohorting @cohorting_disabled = true - redis.hset(experiment_config_key, :cohorting, true) + redis.hset(experiment_config_key, :cohorting, true.to_s) end def enable_cohorting @cohorting_disabled = false - redis.hset(experiment_config_key, :cohorting, false) + redis.hset(experiment_config_key, :cohorting, false.to_s) end protected diff --git a/spec/experiment_spec.rb b/spec/experiment_spec.rb index 78e930ca..36175d4d 100644 --- a/spec/experiment_spec.rb +++ b/spec/experiment_spec.rb @@ -68,7 +68,7 @@ def alternative(color) experiment_start_time = Time.parse("Sat Mar 03 14:01:03") expect(Time).to receive(:now).twice.and_return(experiment_start_time) experiment.save - Split.redis.hset(:experiment_start_times, experiment.name, experiment_start_time) + Split.redis.hset(:experiment_start_times, experiment.name, experiment_start_time.to_s) expect(Split::ExperimentCatalog.find("basket_text").start_time).to eq(experiment_start_time) end From 72b9d892316adb825497906470a912b9ed21043f Mon Sep 17 00:00:00 2001 From: Konrad Narewski Date: Mon, 12 Sep 2022 15:56:16 +0200 Subject: [PATCH 2/2] Use empty string directly instead of casting nil MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: André Luis Leal Cardoso Junior --- lib/split/alternative.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/split/alternative.rb b/lib/split/alternative.rb index 1ba0ebff..a9a673c9 100644 --- a/lib/split/alternative.rb +++ b/lib/split/alternative.rb @@ -166,7 +166,7 @@ def validate! end def reset - Split.redis.hmset key, "participant_count", 0, "completed_count", 0, "recorded_info", nil.to_s + Split.redis.hmset key, "participant_count", 0, "completed_count", 0, "recorded_info", "" unless goals.empty? goals.each do |g| field = "completed_count:#{g}"