Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Kredis#redis_version #149

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion lib/kredis.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
14 changes: 14 additions & 0 deletions lib/kredis/info.rb
Original file line number Diff line number Diff line change
@@ -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
heka1024 marked this conversation as resolved.
Show resolved Hide resolved
end
10 changes: 10 additions & 0 deletions test/kredis/info_test.rb
Original file line number Diff line number Diff line change
@@ -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