I have an array RedisValue[] returned from the StackExchange.Redis client. I want to take each of the values (which are actually JSON strings) in the array and join them together to get a valid JSON string that I can return to the client.
Here's what I want to do...
var results = redis.HashGet("srch", ArrayOfRedisKeys[]);
string returnString = "[" + string.Join(results, ",") + "]";
However, this doesn't work because results is an array of RedisValue not an array of string. Is there a straight-forward and performant way to do this other than just iterating the RedisValue array?
Not currently, but I have just pushed the following extension method into ExtensionMethods.cs:
static readonly string[] nix = new string[0];
/// <summary>
/// Create an array of strings from an array of values
/// </summary>
public static string[] ToStringArray(this RedisValue[] values)
{
if (values == null) return null;
if (values.Length == 0) return nix;
return Array.ConvertAll(values, x => (string)x);
}
So: in the next build, you can just use results.ToStringArray(). Until then, you could just copy the above locally.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With