Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Convert String[] array to RedisKey[] array

Trying to use

KeyDelete(RedisKey[] keys, CommandFlags flags = CommandFlags.None);

I have array of string[] , I am not seeing any examples out there when I search for converting these data types. I am not even sure how to create a new RedisKey.

Tried

RedisKey redisKey = new RedisKey("d");

above does not work, any suggestions?

like image 709
Justin Homes Avatar asked Feb 09 '15 16:02

Justin Homes


1 Answers

From the source code RedisKey has an implicit conversion from string:

/// <summary>
/// Create a key from a String
/// </summary>
public static implicit operator RedisKey(string key)
{
    if (key == null) return default(RedisKey);
    return new RedisKey(null, key);
}

So you can create one by

RedisKey key = "hello";

or

var key = (RedisKey)"hello";

To convert an IEnumerable<string> to RedisKey[], you can do:

var keys = strings.Select(key => (RedisKey)key).ToArray();
like image 66
dav_i Avatar answered Sep 20 '22 21:09

dav_i