19

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?

NXT
  • 1,861
  • 22
  • 29
Justin Homes
  • 3,449
  • 8
  • 44
  • 69
  • There is an implicit conversion defined between `RedisKey` and `string`. If you want a key with the value of "d", just make a direct assignment, `RedisKey redisKey = "d"` https://github.com/StackExchange/StackExchange.Redis/blob/master/Docs/KeysValues.md – Preston Guillot Feb 09 '15 at 16:18

1 Answers1

35

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();
dav_i
  • 25,285
  • 17
  • 94
  • 128