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

Updated JedisConfig to use environment variables #72

Merged
merged 2 commits into from
Apr 22, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,20 +1,50 @@
package com.linkurlshorter.urlshortener.config;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import redis.clients.jedis.JedisPool;
import redis.clients.jedis.JedisPoolConfig;

import java.time.Duration;

/**
* Configuration class for setting up Jedis, a Java Redis client.
*
* <p>This class configures a JedisPool bean, which serves as a connection pool to manage connections
* to the Redis server. It specifies the Redis server host and port using properties defined in
* the application.properties file. Additionally, it configures various connection pool parameters
* such as maximum total connections, maximum idle connections, and eviction settings to optimize
* connection management and performance.
*
* @author Egor Sivenko
* @see redis.clients.jedis.JedisPool
* @see redis.clients.jedis.JedisPoolConfig
*/
@Configuration
public class JedisConfig {

@Value("${REDIS_HOST:}")
private String host;

@Value("${REDIS_PORT:0}")
private int port;

/**
* Creates and configures a JedisPool bean for managing Redis connections.
*
* @return the configured JedisPool bean
*/
@Bean
public JedisPool jedisPool() {
return new JedisPool(buildPoolConfig(), "localhost", 6379);
return new JedisPool(buildPoolConfig(), host, port);
}

/**
* Builds and configures the JedisPoolConfig for the JedisPool bean.
*
* @return the configured JedisPoolConfig object
*/
private JedisPoolConfig buildPoolConfig() {
JedisPoolConfig poolConfig = new JedisPoolConfig();
poolConfig.setMaxTotal(128);
Expand Down
Loading