eddy0223
eddy0223

Reputation: 113

How to convert a Redis ArrayRedisResult into a C# array?

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

Upvotes: 5

Views: 2356

Answers (1)

Matías Fidemraizer
Matías Fidemraizer

Reputation: 64923

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");

Upvotes: 7

Related Questions