diff --git a/.idea/misc.xml b/.idea/misc.xml
index 8dc554d..e267411 100644
--- a/.idea/misc.xml
+++ b/.idea/misc.xml
@@ -8,7 +8,7 @@
-
+
diff --git a/pom.xml b/pom.xml
index b4c0aac..228cd7b 100644
--- a/pom.xml
+++ b/pom.xml
@@ -9,23 +9,38 @@
1.0-SNAPSHOT
- 17
- 17
+ 21
+ 21
UTF-8
+
redis.clients
jedis
5.1.5
+
org.junit.jupiter
junit-jupiter
5.8.1
test
+
+ org.testcontainers
+ testcontainers
+ 1.21.3
+ test
+
+
+ org.testcontainers
+ junit-jupiter
+ 1.21.3
+ test
+
+
\ No newline at end of file
diff --git a/src/main/java/org/redis/Main.java b/src/main/java/org/redis/Main.java
index 68b3db6..d808dbb 100644
--- a/src/main/java/org/redis/Main.java
+++ b/src/main/java/org/redis/Main.java
@@ -1,7 +1,19 @@
package org.redis;
+import org.redis.service.RedisMap;
+
+
public class Main {
public static void main(String[] args) {
- System.out.println("Hello world!");
+
+ RedisMap redisMap = new RedisMap("redisMap");
+ redisMap.put("key1", "value1");
+ redisMap.put("key2", "value2");
+ redisMap.put("key3", "value3");
+ redisMap.entrySet().forEach(System.out::println);
+ redisMap.keySet().forEach(System.out::println);
+ redisMap.values().forEach(System.out::println);
+
}
+
}
\ No newline at end of file
diff --git a/src/main/java/org/redis/service/JedisProducer.java b/src/main/java/org/redis/service/JedisProducer.java
new file mode 100644
index 0000000..0a30fa4
--- /dev/null
+++ b/src/main/java/org/redis/service/JedisProducer.java
@@ -0,0 +1,29 @@
+package org.redis.service;
+
+import redis.clients.jedis.JedisPooled;
+
+import java.io.InputStream;
+import java.util.Properties;
+
+public class JedisProducer {
+
+ public JedisPooled getJedis() {
+
+ try (InputStream input = JedisProducer.class.getClassLoader()
+ .getResourceAsStream("redis.properties")) {
+ Properties prop = new Properties();
+ prop.load(input);
+
+ return new JedisPooled(
+ prop.getProperty("redis.host"),
+ Integer.parseInt(prop.getProperty("redis.port")));
+
+ } catch (Exception e) {
+ throw new RuntimeException("Ошибка инициализации Redis", e);
+ }
+ }
+
+}
+
+
+
diff --git a/src/main/java/org/redis/service/RedisMap.java b/src/main/java/org/redis/service/RedisMap.java
new file mode 100644
index 0000000..cb0ab62
--- /dev/null
+++ b/src/main/java/org/redis/service/RedisMap.java
@@ -0,0 +1,90 @@
+package org.redis.service;
+
+import redis.clients.jedis.JedisPooled;
+
+import java.util.*;
+
+public class RedisMap implements Map {
+
+ private final JedisPooled jedis;
+
+ private final String redisKey;
+
+ public RedisMap(String keyMap) {
+ jedis = new JedisProducer().getJedis();
+ this.redisKey = keyMap;
+ }
+
+ public RedisMap(JedisPooled jedis, String keyMap) {
+ this.jedis = jedis;
+ this.redisKey = keyMap;
+ }
+
+ @Override
+ public int size() {
+ return (int) jedis.hlen(redisKey);
+ }
+
+ @Override
+ public boolean isEmpty() {
+ return size() == 0;
+ }
+
+ @Override
+ public boolean containsKey(Object key) {
+ return jedis.hexists(redisKey, key.toString());
+ }
+
+ @Override
+ public boolean containsValue(Object value) {
+ return jedis.hvals(redisKey).contains(value.toString());
+ }
+
+ @Override
+ public String get(Object key) {
+ return jedis.hget(redisKey, key.toString());
+ }
+
+ @Override
+ public String put(String key, String value) {
+ String previous = get(key);
+ jedis.hset(redisKey, key, value);
+ return previous;
+ }
+
+ @Override
+ public String remove(Object key) {
+ String previous = get(key);
+ if (previous != null) {
+ jedis.hdel(redisKey, key.toString());
+ }
+ return previous;
+ }
+
+ @Override
+ public void putAll(Map extends String, ? extends String> m) {
+ Map tempMap = new HashMap<>(m);
+ jedis.hset(redisKey, tempMap);
+ }
+
+ @Override
+ public void clear() {
+ jedis.del(redisKey);
+ }
+
+ @Override
+ public Set keySet() {
+ return new HashSet<>(jedis.hkeys(redisKey));
+ }
+
+ @Override
+ public Collection values() {
+ return new ArrayList<>(jedis.hvals(redisKey));
+ }
+
+ @Override
+ public Set> entrySet() {
+ return jedis.hgetAll(redisKey).entrySet();
+ }
+
+}
diff --git a/src/main/resources/redis.properties b/src/main/resources/redis.properties
new file mode 100644
index 0000000..81cd288
--- /dev/null
+++ b/src/main/resources/redis.properties
@@ -0,0 +1,2 @@
+redis.host=localhost
+redis.port=6379
\ No newline at end of file
diff --git a/src/test/java/org/redis/service/RedisMapTest.java b/src/test/java/org/redis/service/RedisMapTest.java
new file mode 100644
index 0000000..78600c6
--- /dev/null
+++ b/src/test/java/org/redis/service/RedisMapTest.java
@@ -0,0 +1,107 @@
+package org.redis.service;
+
+import org.junit.jupiter.api.*;
+
+
+import org.testcontainers.containers.GenericContainer;
+import org.testcontainers.utility.DockerImageName;
+import redis.clients.jedis.JedisPooled;
+
+import java.util.Map;
+
+import static org.junit.jupiter.api.Assertions.*;
+
+
+class RedisMapIntegrationTest {
+
+ private RedisMap redisMap;
+ private static JedisPooled jedis;
+
+ static GenericContainer> redis =
+ new GenericContainer<>(DockerImageName.parse("redis:7.2-alpine"))
+ .withExposedPorts(6379);
+
+ @BeforeAll
+ static void beforeAll() {
+ redis.start();
+
+ jedis = new JedisPooled(
+ redis.getHost(),
+ redis.getFirstMappedPort()
+ );
+ }
+
+ @AfterAll
+ static void afterAll() {
+ if (jedis != null) {
+ jedis.close();
+ }
+ redis.stop();
+ }
+
+ @BeforeEach
+ void setUp() {
+ redisMap = new RedisMap(jedis,"test:map");
+ jedis.del("test:map");
+ }
+
+
+ @Test
+ void testBasicOperations() {
+ assertAll(
+ () -> assertTrue(redisMap.isEmpty()),
+ () -> assertEquals(0, redisMap.size()),
+ () -> assertNull(redisMap.put("key1", "value1")),
+ () -> assertEquals("value1", redisMap.get("key1")),
+ () -> assertEquals(1, redisMap.size()),
+ () -> assertFalse(redisMap.isEmpty()),
+ () -> assertEquals("value1", redisMap.remove("key1")),
+ () -> assertTrue(redisMap.isEmpty())
+ );
+ }
+
+ @Test
+ void testContainsMethods() {
+ redisMap.put("key1", "value1");
+
+ assertAll(
+ () -> assertTrue(redisMap.containsKey("key1")),
+ () -> assertFalse(redisMap.containsKey("none")),
+ () -> assertTrue(redisMap.containsValue("value1")),
+ () -> assertFalse(redisMap.containsValue("none"))
+ );
+ }
+
+ @Test
+ void testPutAll() {
+ Map data = Map.of(
+ "key1", "value1",
+ "key2", "value2",
+ "key3", "value3"
+ );
+
+ redisMap.putAll(data);
+
+ assertAll(
+ () -> assertEquals(3, redisMap.size()),
+ () -> assertEquals(3, redisMap.size()),
+ () -> assertTrue(redisMap.entrySet().containsAll(data.entrySet()))
+ );
+ }
+
+
+ @Test
+ void testClear() {
+ redisMap.put("key1", "value1");
+ redisMap.put("key2", "value2");
+
+ redisMap.clear();
+
+ assertAll(
+ () -> assertEquals(0, redisMap.size()),
+ () -> assertTrue(redisMap.isEmpty()),
+ () -> assertFalse(jedis.exists("test:map"))
+ );
+ }
+
+}
\ No newline at end of file