Skip to content

Commit

Permalink
feat: added function to remove data in Redis
Browse files Browse the repository at this point in the history
  • Loading branch information
Sleon4 committed Oct 24, 2024
1 parent e3673e2 commit 5dfff2a
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
18 changes: 18 additions & 0 deletions src/LionBundle/Helpers/Redis.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
Expand Down
14 changes: 14 additions & 0 deletions tests/Helpers/RedisTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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']])]
Expand Down

0 comments on commit 5dfff2a

Please sign in to comment.