From e3673e236513f3c537d496c9c4a5596b6cab4224 Mon Sep 17 00:00:00 2001 From: Sleon4 Date: Thu, 24 Oct 2024 11:34:25 -0500 Subject: [PATCH 1/2] chore: Redis client visibility is modified --- src/LionBundle/Helpers/Redis.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/LionBundle/Helpers/Redis.php b/src/LionBundle/Helpers/Redis.php index e046cb2..c9d4a6b 100644 --- a/src/LionBundle/Helpers/Redis.php +++ b/src/LionBundle/Helpers/Redis.php @@ -29,7 +29,7 @@ class Redis * * @var Client $client */ - private Client $client; + protected Client $client; /** * [Time in seconds to expire the cache] From 5dfff2a4871ad9f5d29a55a2558885b20ffaafea Mon Sep 17 00:00:00 2001 From: Sleon4 Date: Thu, 24 Oct 2024 11:46:01 -0500 Subject: [PATCH 2/2] feat: added function to remove data in Redis --- src/LionBundle/Helpers/Redis.php | 18 ++++++++++++++++++ tests/Helpers/RedisTest.php | 14 ++++++++++++++ 2 files changed, 32 insertions(+) diff --git a/src/LionBundle/Helpers/Redis.php b/src/LionBundle/Helpers/Redis.php index c9d4a6b..768f312 100644 --- a/src/LionBundle/Helpers/Redis.php +++ b/src/LionBundle/Helpers/Redis.php @@ -147,6 +147,24 @@ public function get(string $key): ?array return $this->toArray($this->client->get($key)); } + /** + * Removes a value from the Redis database + * + * @param string $key [Index name] + * + * @return Redis + */ + public function del(string $key): Redis + { + $this->connect(); + + $key = trim($key); + + $this->client->del($key); + + return $this; + } + /** * Clear all cached data * diff --git a/tests/Helpers/RedisTest.php b/tests/Helpers/RedisTest.php index 5fa90c7..c42becf 100644 --- a/tests/Helpers/RedisTest.php +++ b/tests/Helpers/RedisTest.php @@ -133,6 +133,20 @@ public function get(string $key, array $json): void $this->assertSame($json['name'], $return['name']); } + #[Testing] + #[TestWith(['key' => 'data', 'json' => ['name' => 'root']])] + #[TestWith(['key' => 'data', 'json' => ['name' => 'lion']])] + public function del(string $key, array $json): void + { + $value = $this->redis + ->setTime(self::REDIS_TIME_CACHE) + ->set($key, $json) + ->del($key) + ->get($key); + + $this->assertNull($value); + } + #[Testing] #[TestWith(['key' => 'data', 'json' => ['name' => 'root']])] #[TestWith(['key' => 'data', 'json' => ['name' => 'lion']])]