-
Notifications
You must be signed in to change notification settings - Fork 18
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
xadd
type signature is confusingly permissive
#40
Comments
I was really hoping it wouldn’t affect this shard, but it looks like it has. The problem is that one of the recent releases of Crystal (I think it was 1.6, actually) has caused a lot of problems with recursive type aliases. They’ve been problematic in some ways for a while and they want to remove them from the language — the issues that link to that one illustrate a lot of the problems they can cause. I had to replace recursive aliases in one of my other shards with the I used the recursive alias in this shard specifically because it simplified things a bit not to have the extra layer in between to unwrap. |
Not sure if I'm misunderstanding the internal code of But instead, it was treating the array like a value to the key But I changed the code to work like how I expected: data.each do |key, val|
command << key.to_s << value
end to data.each do |key, value|
if value.is_a? Array
command.concat value
else
command << key.to_s << value
end
end it works as intended. If this is desired behavior, I can submit a PR |
Oh, okay, looks like I misread the problem this morning and assumed it was the same thing I'd seen elsewhere with recursive type aliases. This is a completely different thing. I had a look back at the code (I haven't used Redis streams in a while due to this bug) and noticed that there isn't an overload at all for passing arrays. See these method signatures for Since the Because of this, in order to get your change to work as intended, I had to explicitly specify a keyword argument for the array so it wouldn't assign it to redis.xadd "my-stream", "*", data: test.flat_map {|k, v| [k, v]} This actually works no matter what the key is, though, because it's ignored when the value is an array. So it ends up working by accident based on the calling convention you used, which is pretty much the reason it works now — it was based on the calling convention I used when I wrote the method. There are also other bugs with the hash overloads. Namely, they won't compile at all currently due to a namespacing issue. Specifically, the Unfortunately, the code as it sits is too sloppily written and needs to be tightened up significantly. I think we could probably add more overloads here (the keyword-argument overload falls down if you want a |
xadd
type signature is confusingly permissive
To be clear, your example works when using the keyword-argument overload for redis = Redis::Client.new
redis.xadd "my-stream", "*", name: "Homie", curr: "USD" Unfortunately, this requires you to know the keys you'll be assigning to your stream entries at compile time, which isn't always feasible, so I still think the method signatures for this command should be tightened up. |
Hi,
Sorry if this is a noob question, just been playing around with this shard, and I'm not sure why I'm encountering this error
It's throwing this error:
but
Redis::Value
is defined as:Should this imply that
Array(String)
is a validRedis::Value
?The text was updated successfully, but these errors were encountered: