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

Allows #del to receive a Array(RedisValue). #105

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
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
5 changes: 5 additions & 0 deletions spec/redis_namespace_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 6 additions & 0 deletions spec/redis_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
10 changes: 5 additions & 5 deletions src/redis/commands.cr
Original file line number Diff line number Diff line change
Expand Up @@ -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:
#
Expand Down Expand Up @@ -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("::")
Expand All @@ -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}") }
Expand Down