41 lines
898 B
PHP
41 lines
898 B
PHP
<?php
|
|
|
|
namespace App\Service;
|
|
|
|
use App\Service\RedisClientProvider;
|
|
|
|
class JsonCache
|
|
{
|
|
protected $redis;
|
|
protected $jo_json_info_key;
|
|
|
|
public function __construct(RedisClientProvider $redis_prov, $jo_json_info_key)
|
|
{
|
|
$this->redis = $redis_prov->getRedisClient();
|
|
$this->jo_json_info_key = $jo_json_info_key;
|
|
}
|
|
|
|
public function addJOJsonInfo($jo_id, $jo_data)
|
|
{
|
|
$key = $jo_id;
|
|
|
|
$this->redis->hset($this->jo_json_info_key, $key, $jo_data);
|
|
}
|
|
|
|
public function findJOJsonInfo($jo_id)
|
|
{
|
|
$jo_data = '';
|
|
|
|
$key = $jo_id;
|
|
|
|
// check if JO id is in redis hash
|
|
$is_exist = $this->redis->hexists($this->jo_json_info_key, $key);
|
|
if ($is_exist)
|
|
{
|
|
// get the data
|
|
$jo_data = $this->redis->hget($this->jo_json_info_key, $key);
|
|
}
|
|
|
|
return $jo_data;
|
|
}
|
|
}
|