Skip to content
This repository was archived by the owner on Nov 16, 2022. It is now read-only.
This repository was archived by the owner on Nov 16, 2022. It is now read-only.

RedisCommandException: Multi-key operations must involve a single slot while storing PersistedGrant  #28

@vadimdr

Description

@vadimdr

Hi,

I am getting the following exception while trying to perform the Authorization code flow with IdentityServer4 configured to use the Redis as an operational store:

RedisCommandException: Multi-key operations must involve a single slot; keys can use 'hash tags' to help this, i.e. '{/users/12345}/account' and '{/users/12345}/contacts' will always be in the same slot
IdentityServer4.Contrib.RedisStore.Stores.PersistedGrantStore.StoreAsync(PersistedGrant grant)
IdentityServer4.Stores.DefaultGrantStore<T>.StoreItemAsync(string key, T item, string clientId, string subjectId, DateTime created, Nullable<DateTime> expiration)
IdentityServer4.Stores.DefaultGrantStore<T>.CreateItemAsync(T item, string clientId, string subjectId, DateTime created, int lifetime)
IdentityServer4.ResponseHandling.AuthorizeResponseGenerator.CreateCodeFlowResponseAsync(ValidatedAuthorizeRequest request)
...

My instance of IdentityServer4 based server is configured to use Redis as an operational store:

.AddOperationalStore(options =>
                {
                    options.KeyPrefix = IdSrvConstants.IdentityServerSolution;
                    options.RedisConnectionMultiplexer = scope.ServiceProvider.GetRequiredService<IConnectionMultiplexer>();
                });

and the Redis is AWS ElasticCache clustered Redis instance.
The same code works fine on a single-node Redis.

Based on my understanding, the problem is related to the way the PersistedGrantStore generates the key's names - it does not use the keys hash tags (see https://redis.io/topics/cluster-spec#keys-hash-tags) in order to make sure all the keys will involve a single slot while performing a single Redis transaction.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions