45 lines
1.1 KiB
PHP
45 lines
1.1 KiB
PHP
<?php
|
|
|
|
namespace Lts\Sales\Helper;
|
|
|
|
use Credis_Client;
|
|
use Magento\Framework\App\DeploymentConfig;
|
|
|
|
class CredisStorage
|
|
{
|
|
private Credis_Client $redis;
|
|
|
|
public function __construct(DeploymentConfig $deploymentConfig)
|
|
{
|
|
$options = (array) $deploymentConfig->get(
|
|
'cache/frontend/default/backend_options'
|
|
);
|
|
|
|
$this->redis = new Credis_Client(
|
|
$options['server'] ?? '127.0.0.1',
|
|
(int)($options['port'] ?? 6379),
|
|
(float)($options['timeout'] ?? 2.5),
|
|
'',
|
|
(int)($options['database'] ?? 0),
|
|
$options['password'] ?? null
|
|
);
|
|
|
|
if (!empty($options['key_prefix'])) {
|
|
$this->redis->setPrefix($options['key_prefix']);
|
|
}
|
|
}
|
|
|
|
public function get(string $key)
|
|
{
|
|
return $this->redis->SMEMBERS($key);
|
|
}
|
|
|
|
public function set(string $key, $value)
|
|
{
|
|
$this->redis->sAdd($key, $value);
|
|
}
|
|
|
|
public function isExist(string $key, $value) {
|
|
return $this->redis->sIsMember($key, $value);
|
|
}
|
|
} |