From b5c6604f23abac8e60fa1d5b1fba3244493e4efe Mon Sep 17 00:00:00 2001 From: Ilya Lisov Date: Sun, 21 Jan 2024 00:47:36 +0300 Subject: [PATCH] #19 Add constructors --- .../jwt/storage/RedisTokenStorageImpl.java | 51 ++++++++++++++++++- 1 file changed, 49 insertions(+), 2 deletions(-) diff --git a/src/main/java/io/github/ilyalisov/jwt/storage/RedisTokenStorageImpl.java b/src/main/java/io/github/ilyalisov/jwt/storage/RedisTokenStorageImpl.java index 9e878b1..48d419b 100644 --- a/src/main/java/io/github/ilyalisov/jwt/storage/RedisTokenStorageImpl.java +++ b/src/main/java/io/github/ilyalisov/jwt/storage/RedisTokenStorageImpl.java @@ -5,6 +5,7 @@ import io.github.ilyalisov.jwt.config.redis.RedisSchema; import redis.clients.jedis.Jedis; import redis.clients.jedis.JedisPool; +import redis.clients.jedis.JedisPoolConfig; /** * Implementation of TokenStorage based on Redis. @@ -22,7 +23,7 @@ public class RedisTokenStorageImpl implements TokenStorage { private final RedisSchema redisSchema; /** - * Creates an object with provided JedisPool and DefaultRedisSchema. + * Creates an object. * * @param jedisPool JedisPool object */ @@ -34,7 +35,7 @@ public RedisTokenStorageImpl( } /** - * Creates an object with provided JedisPool and RedisSchema. + * Creates an object. * * @param jedisPool JedisPool object * @param redisSchema RedisSchema object @@ -47,6 +48,52 @@ public RedisTokenStorageImpl( this.redisSchema = redisSchema; } + /** + * Creates an object. + * + * @param host Redis host + * @param port Redis port + */ + public RedisTokenStorageImpl( + final String host, + final int port + ) { + JedisPoolConfig config = new JedisPoolConfig(); + config.setJmxEnabled(false); + this.jedisPool = new JedisPool( + config, + host, + port + ); + this.redisSchema = new DefaultRedisSchema(); + } + + /** + * Creates an object. + * + * @param host Redis host + * @param port Redis port + * @param user Redis username + * @param password Redis password + */ + public RedisTokenStorageImpl( + final String host, + final int port, + final String user, + final String password + ) { + JedisPoolConfig config = new JedisPoolConfig(); + config.setJmxEnabled(false); + this.jedisPool = new JedisPool( + config, + host, + port, + user, + password + ); + this.redisSchema = new DefaultRedisSchema(); + } + @Override public void save( final String token,