Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions CacheManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,4 @@ public function lpush(string $key, string $value){
$cm->connect('somehost','121');
$cm->set('one','1');
$cm->lpush('two','2'); // generates exception
echo $cm->get('one');


echo $cm->get('one');
57 changes: 57 additions & 0 deletions solution_tansen.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
<?php
/**
* Created by PhpStorm.
* User: Tansen
* Date: 05.09.21
* Time: 23:52
*/

class redisCacheManager
{
private $cache;
function __construct(string $host,string $port){
$this->cache=new \Redis();
$this->cache->connect($host,$port);
}

public function set(string $key, string $value, string $ttl=null){
$this->cache->set($key,$value,$ttl);
}

public function get(string $key){
return $this->cache->get($key);
}

public function lpush(string $key, string $value){
$this->cache->lPush($key,$value);
}
}


class memCacheManager
{
private $cache;
function __construct(string $host,string $port){
$this->cache=new \Memcache();
$this->cache->connect($host,$port);
}

public function set(string $key, string $value, string $is_compressed=null, string $ttl=null){
$this->cache->set($key,$value,$is_compressed,$ttl);
}

public function get(string $key){
return $this->cache->get($key);
}

}

$cmerdis=new redisCacheManager('somehost','121');
$cmredis->set('one','1');
$cmredis->lpush('two','1');
$cmredis->lpush('two','2');
echo $cmredis->get('one');

$memcm=new memCacheManager('somehost','121');
$memcm->set('one','1');
echo $memcm->get('one');