5

I would like to convert an array table returned by Redis to be used in my C# code. How can I do that ?

After debugging the code, I can see that he returns an ArrayRedisResult

string script = @"return redis.call('HGETALL', @key)";
LuaScript lScript = LuaScript.Prepare(script);
var lLScript = lScript.Load("myServerinformation");
var result = lLScript.Evaluate("myDatabaseInformation", "myKey");

Thank in advance

1 Answer 1

8

Taken from other answer where OP said in some comment:

the million dollars question is how to convert it to a type array that C# will understand?

You'll cry when you realize that your question has a very easy answer: ArrayRedisResult can be casted to a lot of array types: string[], bool[]... Check its source code.

At the end of the day, it's just about coding an explicit cast:

var result = (string[])lLScript.Evaluate("myDatabaseInformation", "myKey");
Sign up to request clarification or add additional context in comments.

2 Comments

Thank you very much. Truly the answer wasn't far.
@eddy0223 Yeah. We should ask Marc Gravell to know why he decided to implement these operators as explicit instead of implicit. With implicit operators, you could type the result as string[] and you wouldn't need an explicit cast ;P

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.