Skip to content

Commit

Permalink
Merge pull request #95 from lion-packages/new
Browse files Browse the repository at this point in the history
Redis Support
  • Loading branch information
GabrielPalac authored Oct 24, 2024
2 parents c94783d + 5dfff2a commit 2519a7e
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 1 deletion.
20 changes: 19 additions & 1 deletion src/LionBundle/Helpers/Redis.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class Redis
*
* @var Client $client
*/
private Client $client;
protected Client $client;

/**
* [Time in seconds to expire the cache]
Expand Down 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 2519a7e

Please sign in to comment.