Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Document Support for Key Prefixes in RedisDistributedLock #178

Open
teomane opened this issue Jan 3, 2024 · 3 comments
Open

Document Support for Key Prefixes in RedisDistributedLock #178

teomane opened this issue Jan 3, 2024 · 3 comments
Labels
cleanup Code cleanup and other maintenance changes that do not affect runtime behavior redis

Comments

@teomane
Copy link

teomane commented Jan 3, 2024

Hello,

I'm encountering an issue with RedisDistributedLock. Currently, I am using a single Redis instance for multiple environments (such as dev and test). My goal is to use the same key in the TryAcquireLockAsync method but with different prefixes for each environment.

For example, in the application code, I have:
_distributedLockProvider.AcquireLockAsync(“DO_SOMETHING”);

However, in Redis, I need the keys to be environment-specific, like dev:DO_SOMETHING for the development environment and test:DO_SOMETHING for the test environment.

As a reference, in StackExchangeRedisCache, this is achieved as follows:

services.AddStackExchangeRedisCache(options =>
{
    options.Configuration = “your_configuration”;
    options.InstanceName = $"{Environment}:";
});

In this case, InstanceName serves as a prefix.

Would it be a good idea to consider adding an option for this in RedisDistributedSynchronizationOptionsBuilder during startup configuration?

@madelson
Copy link
Owner

madelson commented Jan 3, 2024

Hi @teomane thanks for your interest in the library!

I wonder if the approach described here could work for you: #65

This leverages native autoprefixing support from the Redis client.

@teomane
Copy link
Author

teomane commented Jan 4, 2024

Hi @madelson ,

It works for me! Thank you for your response.

@madelson madelson added cleanup Code cleanup and other maintenance changes that do not affect runtime behavior and removed enhancement needs-information labels Jan 4, 2024
@madelson
Copy link
Owner

madelson commented Jan 4, 2024

Great. I’ll keep this issue open as a reminder to add a note about this in the documentation

@madelson madelson changed the title Support for Environment-Specific Key Prefixes in RedisDistributedLock Document Support for Key Prefixes in RedisDistributedLock Jan 4, 2024
@madelson madelson added the redis label Mar 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cleanup Code cleanup and other maintenance changes that do not affect runtime behavior redis
Projects
None yet
Development

No branches or pull requests

2 participants