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

Egor Skriptunoff
  • 23,359
  • 2
  • 34
  • 64
eddy0223
  • 103
  • 1
  • 1
  • 7

1 Answers1

7

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");
andreycha
  • 383
  • 4
  • 22
Matías Fidemraizer
  • 63,804
  • 18
  • 124
  • 206
  • Thank you very much. Truly the answer wasn't far. – eddy0223 Mar 18 '16 at 20:32
  • @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 – Matías Fidemraizer Mar 18 '16 at 20:37