Skip to content

IDatabase.KeyTypeAsync returns Unknown instead of None when the key does not exist #3156

Description

@jamir-araujo

I updated the StackExchange.Redis package from version 2.8.16 to 3.1.3, and now, in my functional tests, calls to KeyTypeAsync return Unknown instead of None when the key does not exist.

This behavior occurs in the following versions:

Package version
3.0.0
3.0.7
3.0.11
3.0.17
3.0.25
3.1.0
3.1.3

I tested version 2.13.17, which exhibits the expected behavior (returns None).

Code to reproduce

using StackExchange.Redis;

var connection = await ConnectionMultiplexer.ConnectAsync("127.0.0.1");
var database = connection.GetDatabase(0);

var type = await database.KeyTypeAsync("foo");

Console.WriteLine("{0}", type);

This appears to be an error in the token passed to the AsciiHashAttribute of the RedisType enum.

namespace StackExchange.Redis
{
    public enum RedisType
    {
        [AsciiHash("")]
        None,

        [AsciiHash("string")]
        String,

        //...
    }
}

As I understand it, RedisTypeMetadata.TryParse converts the command response according to the token defined in AsciiHash. For RedisType.None, an empty string is expected; however, the Redis TYPE command returns "none" when the key does not exist.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions