imperugo / StackExchange.Redis.Extensions

MIT License
607 stars 177 forks source link

DataBase Number and Pool Size #546

Closed akshatchhangani closed 9 months ago

akshatchhangani commented 1 year ago

Hi Team, I am using StackExchange Redis Library. I have doubts like,

  1. what is the pool size for Redis ?
  2. What is the meaning of connecting to any database, say 0. What difference will it make if I connect to database 2 instead of database 0?
  3. How can we connect to multiple databases in a single micro service?
  4. I am having Redis cluster created in aws elastic cache. I am connecting to that cluster in my .NET core microservice, but it is very frequently creating new connections to Redis. What could be the issue?
imperugo commented 9 months ago

Hi @akshatchhangani

here some answers:

1) Rea here the documentation https://github.com/imperugo/StackExchange.Redis.Extensions/blob/master/doc/configuration/connection-pool.md

2) I think you are referring to the property Database of RedisConfiguration. This property sets the default database to use for the operations.

Basically you can set 3 and, when you do something like this

var result = await redisDatabase.GetAsync<MyClass?>(cacheKey, CommandFlags.PreferReplica);

here redisDatabase is an instance of IRedisDatabase

this command will be work on database 3.

3) You can access to any database of redis in any moment. Is enough to use IRedisClient instead of IRedisDatabase and choise the database you prefer

redisClient.Db5.AddAsync(......

4) I also using this with AWS ElasticCache but I neved did this issue. I need more information in order to help you but is seems like you are not registering the DI as Singleton so the connection will be created any time you connect or there are connection issues to the Redis database.

Let me know if is enough or not.

Thanks