Code Duplication    Length = 38-39 lines in 2 locations

eZ/Bundle/EzPublishCoreBundle/Cache/Driver/Redis/RedisIgbinaryLzf.php 1 location

@@ 17-55 (lines=39) @@
14
15
use Stash\Driver\Redis as StashRedis;
16
17
class RedisIgbinaryLzf extends StashRedis
18
{
19
    public function getData($key)
20
    {
21
        $data = $this->redis->get($this->makeKeyString($key));
22
        if (false !== $data) {
23
            return igbinary_unserialize(lzf_decompress($data));
24
        }
25
26
        return $data;
27
    }
28
29
    public function storeData($key, $data, $expiration)
30
    {
31
        lzf_optimized_for(0);
32
33
        $store = lzf_compress(igbinary_serialize(array('data' => $data, 'expiration' => $expiration)));
34
        if (null === $expiration) {
35
            return $this->redis->set($this->makeKeyString($key), $store);
36
        } else {
37
            $ttl = $expiration - time();
38
39
            // Prevent us from even passing a negative ttl'd item to redis,
40
            // since it will just round up to zero and cache forever.
41
            if ($ttl < 1) {
42
                return true;
43
            }
44
45
            return $this->redis->setex($this->makeKeyString($key), $ttl, $store);
46
        }
47
    }
48
49
    public static function isAvailable()
50
    {
51
        return class_exists('Redis', false)
52
            && extension_loaded('igbinary')
53
            && extension_loaded('lzf');
54
    }
55
}
56

eZ/Bundle/EzPublishCoreBundle/Cache/Driver/Redis/RedisSerializeLzf.php 1 location

@@ 17-54 (lines=38) @@
14
15
use Stash\Driver\Redis as StashRedis;
16
17
class RedisSerializeLzf extends StashRedis
18
{
19
    public function getData($key)
20
    {
21
        $data = $this->redis->get($this->makeKeyString($key));
22
        if (false !== $data) {
23
            return unserialize(lzf_decompress($data));
24
        }
25
26
        return $data;
27
    }
28
29
    public function storeData($key, $data, $expiration)
30
    {
31
        lzf_optimized_for(0);
32
33
        $store = lzf_compress(serialize(array('data' => $data, 'expiration' => $expiration)));
34
        if (null === $expiration) {
35
            return $this->redis->set($this->makeKeyString($key), $store);
36
        } else {
37
            $ttl = $expiration - time();
38
39
            // Prevent us from even passing a negative ttl'd item to redis,
40
            // since it will just round up to zero and cache forever.
41
            if ($ttl < 1) {
42
                return true;
43
            }
44
45
            return $this->redis->setex($this->makeKeyString($key), $ttl, $store);
46
        }
47
    }
48
49
    public static function isAvailable()
50
    {
51
        return class_exists('Redis', false)
52
            && extension_loaded('lzf');
53
    }
54
}
55