2

I'm new to Elixir. I use the redix library to work with Redis. I can't manage to execute MGET command properly. This code works:

Like4uElixir.RedixPool.command(["MGET", "a", "b", "c"])

- it returns 3 values from Redis. But this code doesn't work:

keys = ["a", "b", "c"]
Like4uElixir.RedixPool.command(["MGET", keys])

But I have all the keys in array. How can I convert my array to a number of function arguments?

2
  • If @Gazler answered your question, you should accept his answer as the right one. Commented Jan 26, 2016 at 15:59
  • @OnorioCatenacci done it. Didn't see the button first :( Commented Jan 27, 2016 at 10:16

1 Answer 1

7

You're code samples aren't the same. You are creating a nested list instead of creating a single list with 4 elements.

You're second example does:

["MGET", ["a", "b", "c"]]

You want to do:

keys = ["a", "b", "c"]
Like4uElixir.RedixPool.command(["MGET" | keys])
#or Like4uElixir.RedixPool.command(["MGET"] ++ keys)
Sign up to request clarification or add additional context in comments.

4 Comments

OMG, so easy! :) it was my typo, thank you. I thougth(don't know why) it was function arguments, not a list.
Slightly more idiomatic maybe ["MGET" | keys]. Also s/you're/your/ ;-)
@cdegroot Thanks for the suggestions.
The use of the cons operator is more idiomatic. However, if you already had a list of arguments, you could use Kernel.apply. Just an FYI.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.