From e063958705c4ebf86ec8e6a70fd75e5af76d77ed Mon Sep 17 00:00:00 2001 From: Rodrigo Pinto Date: Sun, 14 Jun 2020 19:02:50 +0200 Subject: [PATCH 1/2] Making use of the Union type for better readability. --- src/redis/commands.cr | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/redis/commands.cr b/src/redis/commands.cr index 95ba4d5..0a32505 100644 --- a/src/redis/commands.cr +++ b/src/redis/commands.cr @@ -1922,7 +1922,7 @@ class Redis key.to_s.gsub(namespaced(""), "").as(RedisValue) end - private def array_without_namespace(keys : (Array(Redis::RedisValue) | Int32 | Int64 | String | Nil)) + private def array_without_namespace(keys : RedisValue) return keys unless keys.is_a?(Array(RedisValue)) keys.map { |key| without_namespace("#{key}") } From c6ee008aafa17d8ea08059e6cba2996bd62b562d Mon Sep 17 00:00:00 2001 From: Rodrigo Pinto Date: Sun, 14 Jun 2020 23:57:55 +0200 Subject: [PATCH 2/2] Allow delete command to support an Array(RedisValue) without break. --- spec/redis_namespace_spec.cr | 5 +++++ spec/redis_spec.cr | 6 ++++++ src/redis/commands.cr | 8 ++++---- 3 files changed, 15 insertions(+), 4 deletions(-) diff --git a/spec/redis_namespace_spec.cr b/spec/redis_namespace_spec.cr index 0e58eb6..1ac15a7 100644 --- a/spec/redis_namespace_spec.cr +++ b/spec/redis_namespace_spec.cr @@ -157,6 +157,11 @@ describe Redis do redis.mset({"foo1" => "bar1", "foo2" => "bar2"}) redis.del(["foo1", "foo2"]).should eq(2) + + redis.set("namespaced::key", 2) + list_of_keys = redis.keys("namespaced::*") + list_of_keys.should eq(["namespaced::key"]) + redis.del(list_of_keys) end it "converts keys to strings" do diff --git a/spec/redis_spec.cr b/spec/redis_spec.cr index ba6168d..8a7adb4 100644 --- a/spec/redis_spec.cr +++ b/spec/redis_spec.cr @@ -157,6 +157,11 @@ describe Redis do redis.mset({"foo1" => "bar1", "foo2" => "bar2"}) redis.del(["foo1", "foo2"]).should eq(2) + + redis.set("namespaced::key", 2) + list_of_keys = redis.keys("namespaced::*") + list_of_keys.should eq(["namespaced::key"]) + redis.del(list_of_keys) end it "converts keys to strings" do @@ -195,6 +200,7 @@ describe Redis do it "#keys" do redis.set("callmemaybe", 1) redis.keys("callmemaybe").should eq(["callmemaybe"]) + redis.del("callmemaybe") end describe "#sort" do diff --git a/src/redis/commands.cr b/src/redis/commands.cr index 0a32505..6fe0e91 100644 --- a/src/redis/commands.cr +++ b/src/redis/commands.cr @@ -561,7 +561,7 @@ class Redis # Returns all keys matching pattern. # - # **Return value**: Array(String), array of keys matching pattern. + # **Return value**: Array(RediSValue), array of keys matching pattern. # # Example: # @@ -1908,11 +1908,11 @@ class Redis destination end - private def namespaced(keys : (Array(String) | Tuple(String, String))) - keys.map { |key| namespaced(key) } + private def namespaced(keys : Array(RedisValue) | Tuple(String, String)) + keys.map { |key| namespaced(key.as(String)) } end - private def namespaced(key : (String | Symbol | Int32)) + private def namespaced(key : String | Symbol | Int32) return key.to_s if @namespace == "" [@namespace, key.to_s].join("::")