NewCache creates a new instance of RedisCache by establishing a connection to Redis. It fetches the configuration, initializes Redis, and returns a Cache instance. Returns an error if the configuration or Redis initialization fails.
()
| 64 | // It fetches the configuration, initializes Redis, and returns a Cache instance. |
| 65 | // Returns an error if the configuration or Redis initialization fails. |
| 66 | func NewCache() (Cache, error) { |
| 67 | // Fetch configuration settings |
| 68 | cfg, err := config.Fetch() |
| 69 | if err != nil { |
| 70 | return nil, err |
| 71 | } |
| 72 | |
| 73 | // Initialize Redis cache with the configured Redis DNS and pool settings |
| 74 | ca, err := newRedisCache([]string{cfg.Redis.Dns}, cfg.Redis.SkipTLSVerify, cfg.Redis.PoolSize, cfg.Redis.MinIdleConns) |
| 75 | if err != nil { |
| 76 | return nil, err |
| 77 | } |
| 78 | return ca, nil |
| 79 | } |
| 80 | |
| 81 | // NewCacheWithClient creates a new RedisCache using an existing Redis client. |
| 82 | // No error is returned because no I/O occurs — the client is already validated. |