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

Cast from Array(Redis::RedisValue) to (String | Nil) failed when using brpoplpush #68

Closed
parruda opened this issue Sep 24, 2018 · 4 comments

Comments

@parruda
Copy link

parruda commented Sep 24, 2018

Forgive me if that's just because I am just learning Crystal, but I am stuck on this.
I am trying to pop something from a queue with:

message = redis.brpoplpush("queue_name", "process_queue_name", 15)

The docs say:

Return value: String, the element being popped from source and pushed to destination. If timeout is reached, nil is returned

Once timeout is reached, I am getting this error:

Exception: cast from Array(Redis::RedisValue) to (String | Nil) failed, at /dev/lib/redis/src/redis/command_execution/value_oriented.cr:37:9:37 (TypeCastError)

What am I doing wrong?

@parruda parruda changed the title ast from Array(Redis::RedisValue) to (String | Nil) failed Cast from Array(Redis::RedisValue) to (String | Nil) failed when using brpoplpush Sep 24, 2018
@maiha
Copy link
Contributor

maiha commented Sep 24, 2018

Hi @parruda , welcome to Crystal!

It seems a problem of the library.
Although I created a PR, please put this monkey patch into your app if you are in hurry. 😃

class Redis
  module CommandExecution
    module ValueOriented
      def string_or_nil_command(request : Request) : String?
        res = command(request)
        res = nil if res.is_a?(Array) && res.empty?
        res.as(String?)
      end
    end
  end
end

@parruda
Copy link
Author

parruda commented Sep 25, 2018

It works.
Thanks a lot @maiha !

@stefanwille
Copy link
Owner

I have merged @maiha's PR and published release 2.1.1. Please try!

@parruda
Copy link
Author

parruda commented Sep 25, 2018

It works. Thanks!

@parruda parruda closed this as completed Sep 25, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants