Reputation: 41
I have 3 applications pointing to single redis endpoint. I want to use separate redis database per application. But when I am trying to set defaultDatabase to 1 or 2 in ConfigurationOption it is still using database 0. I am using stackexchange redis. Code is as given below :
var configurationOptions = new ConfigurationOptions
{
EndPoints = { "myredis.redis.cache.windows.net" },
Password = "xxxxxxxxxxxxxxxxxxx",
Ssl = true,
ConfigurationChannel = "MyRedis",
ChannelPrefix = "MR",
DefaultDatabase = 1,
};
var connectionMultiplexer = ConnectionMultiplexer.Connect(configurationOptions);
var cacheClient = new StackExchangeRedisCacheClient(connectionMultiplexer, new JilSerializer(), database: 1);
Now adding new key to cache using ICacheClient
var user = new User()
{
Id = 100,
Name = "John Doe"
};
var response = cacheClient.Add("mykey", user);
Then retrieving added key from cache
var addedUser= cacheClient.Get<string>("mykey");
Is there anything I am doing wrong? Ideally as per stated in configuration options it should store keys to db1 but it is storing to db0 instead.
Upvotes: 0
Views: 4334
Reputation: 2570
When you retrieve the database object, you should specify the database number. https://stackexchange.github.io/StackExchange.Redis/Basics.html#using-a-redis-database
Upvotes: 0