Skip to content

Commit

Permalink
Add configuration of prefix dynamic for redis (#12)
Browse files Browse the repository at this point in the history
Co-authored-by: Mateus Constanzo <mateus.silva@arquivei.com.br>
  • Loading branch information
mateusconstanzo and Mateus Constanzo authored Sep 28, 2020
1 parent 04de5fe commit b3324b0
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
1 change: 1 addition & 0 deletions config/prometheus.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@
'read_timeout' => env('PROMETHEUS_REDIS_READ_TIMEOUT', 10),
'persistent_connections' => env('PROMETHEUS_REDIS_PERSISTENT_CONNECTIONS', false),
'prefix' => env('PROMETHEUS_REDIS_PREFIX', 'PROMETHEUS_'),
'prefix_dynamic' => env('PROMETHEUS_REDIS_PREFIX_DYNAMIC', true),
],

],
Expand Down
10 changes: 9 additions & 1 deletion src/StorageAdapterFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,13 @@

class StorageAdapterFactory
{
private $hostname;

public function __construct()
{
$this->hostname = gethostname() ?? '';
}

/**
* Factory a storage adapter.
*
Expand Down Expand Up @@ -44,7 +51,8 @@ public function make(string $driver, array $config = []) : Adapter
protected function makeRedisAdapter(array $config) : Redis
{
if (isset($config['prefix'])) {
Redis::setPrefix($config['prefix']);
$prefix = !empty($config['prefix_dynamic']) ? sprintf('%s_%s_', $config['prefix'], $this->hostname) : $config['prefix'];
Redis::setPrefix($prefix);
}

return new Redis($config);
Expand Down

0 comments on commit b3324b0

Please sign in to comment.