From 628be4e16e68493fa6a1ee6cbe5b9f81f0713359 Mon Sep 17 00:00:00 2001 From: Miller Date: Fri, 8 Mar 2024 17:05:58 +0900 Subject: [PATCH 1/2] Add `Kredis#redis_version` --- lib/kredis.rb | 3 ++- lib/kredis/info.rb | 14 ++++++++++++++ test/kredis/info_test.rb | 10 ++++++++++ 3 files changed, 26 insertions(+), 1 deletion(-) create mode 100644 lib/kredis/info.rb create mode 100644 test/kredis/info_test.rb diff --git a/lib/kredis.rb b/lib/kredis.rb index 28f0baf..caf0071 100644 --- a/lib/kredis.rb +++ b/lib/kredis.rb @@ -13,11 +13,12 @@ require "kredis/default_values" require "kredis/types" require "kredis/attributes" +require "kredis/info" require "kredis/railtie" if defined?(Rails::Railtie) module Kredis - include Connections, Namespace, TypeCasting, Types + include Connections, Namespace, TypeCasting, Types, Info extend self autoload :Migration, "kredis/migration" diff --git a/lib/kredis/info.rb b/lib/kredis/info.rb new file mode 100644 index 0000000..ae556ea --- /dev/null +++ b/lib/kredis/info.rb @@ -0,0 +1,14 @@ +# frozen_string_literal: true + +module Kredis::Info + def redis_version + redis_versions.first + end + + def redis_versions + Array.wrap(Kredis.redis.info("server")).tap do |versions| + versions.map! { |v| v["redis_version"] } + versions.map! { |v| Gem::Version.new(v) } + end + end +end diff --git a/test/kredis/info_test.rb b/test/kredis/info_test.rb new file mode 100644 index 0000000..4544dbe --- /dev/null +++ b/test/kredis/info_test.rb @@ -0,0 +1,10 @@ +# frozen_string_literal: true + +require "test_helper" +require "yaml" + +class InfoTest < ActiveSupport::TestCase + test "version" do + assert Kredis.redis_version >= Gem::Version.new("4.0.0") + end +end From 25ab41b4cd63748feeb8fcfacadb37f0c1d0f02f Mon Sep 17 00:00:00 2001 From: Koo Date: Wed, 13 Mar 2024 00:47:33 +0900 Subject: [PATCH 2/2] Apply review Co-authored-by: Jeremy Daer --- lib/kredis/info.rb | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/lib/kredis/info.rb b/lib/kredis/info.rb index ae556ea..03e4e64 100644 --- a/lib/kredis/info.rb +++ b/lib/kredis/info.rb @@ -2,13 +2,6 @@ module Kredis::Info def redis_version - redis_versions.first - end - - def redis_versions - Array.wrap(Kredis.redis.info("server")).tap do |versions| - versions.map! { |v| v["redis_version"] } - versions.map! { |v| Gem::Version.new(v) } - end + Gem::Version.new Kredis.redis.info("server")["redis_version"] end end