Justin Homes
Justin Homes

Reputation: 3799

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?

Upvotes: 20

Views: 10970

Answers (1)

dav_i
dav_i

Reputation: 28107

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

Upvotes: 41

Related Questions