简体   繁体   English

如何将Redis ArrayRedisResult转换为C#数组?

[英]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. 我想将Redis返回的数组表转换为我的C#代码。 How can I do that ? 我怎样才能做到这一点 ?

After debugging the code, I can see that he returns an ArrayRedisResult 调试代码后,我可以看到他返回一个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 预先感谢

Taken from other answer where OP said in some comment: 取自OP在其他评论中所说的其他答案:

the million dollars question is how to convert it to a type array that C# will understand? 百万美元的问题是如何将其转换为C#将理解的类型数组?

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. 当你意识到你的问题有一个非常简单的答案时,你会哭的: ArrayRedisResult可以被转换为很多数组类型: string[]bool[] ... 检查它的源代码。

At the end of the day, it's just about coding an explicit cast: 在一天结束时,它只是编写一个显式的演员:

var result = (string[])lLScript.Evaluate("myDatabaseInformation", "myKey");

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM