Issues (58)

Client/RedisClient.php (16 issues)

1
<?php
2
/*
3
 * This file is part of the Koded package.
4
 *
5
 * (c) Mihail Binev <[email protected]>
6
 *
7
 * Please view the LICENSE distributed with this source code
8
 * for the full copyright and license information.
9
 */
10
11
namespace Koded\Caching\Client;
12
13
use Koded\Caching\Cache;
14
use Koded\Stdlib\Serializer;
15
use function Koded\Caching\verify_key;
16
17
/**
18
 * Class RedisClient uses the Redis PHP extension.
19
 *
20
 */
21
final class RedisClient implements Cache
22
{
23
    use ClientTrait, MultiplesTrait;
24
25
    private Serializer $serializer;
26
27 81
    public function __construct(\Redis $client, Serializer $serializer, int $ttl = null)
28
    {
29 81
        $this->client = $client;
30 81
        $this->serializer = $serializer;
31 81
        $this->ttl = $ttl;
32
    }
33
34 50
    public function get(string $key, mixed $default = null): mixed
35
    {
36 50
        return $this->has($key)
37 41
            ? $this->serializer->unserialize($this->client->get($key))
38 50
            : $default;
39
    }
40
41 55
    public function set(string $key, mixed $value, null|int|\DateInterval $ttl = null): bool
42
    {
43 55
        verify_key($key);
44 55
        $expiration = $this->secondsWithGlobalTtl($ttl);
45 55
        if (null === $ttl && 0 === $expiration) {
46 51
            return $this->client->set($key, $this->serializer->serialize($value));
47
        }
48 5
        if ($expiration > 0) {
49 2
            return $this->client->setex($key, $expiration, $this->serializer->serialize($value));
0 ignored issues
show
The method setex() does not exist on Memcached. Did you maybe mean set()? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

49
            return $this->client->/** @scrutinizer ignore-call */ setex($key, $expiration, $this->serializer->serialize($value));

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
The method setex() does not exist on Koded\Caching\Client\ShmopClient. Did you maybe mean set()? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

49
            return $this->client->/** @scrutinizer ignore-call */ setex($key, $expiration, $this->serializer->serialize($value));

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
The method setex() does not exist on Koded\Caching\Client\FileClient. Did you maybe mean set()? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

49
            return $this->client->/** @scrutinizer ignore-call */ setex($key, $expiration, $this->serializer->serialize($value));

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
The method setex() does not exist on Koded\Caching\Client\MemoryClient. Did you maybe mean set()? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

49
            return $this->client->/** @scrutinizer ignore-call */ setex($key, $expiration, $this->serializer->serialize($value));

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
50
        }
51 3
        $this->client->del($key);
0 ignored issues
show
The method del() does not exist on Koded\Caching\Client\MemoryClient. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

51
        $this->client->/** @scrutinizer ignore-call */ 
52
                       del($key);

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
The method del() does not exist on Koded\Caching\Client\FileClient. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

51
        $this->client->/** @scrutinizer ignore-call */ 
52
                       del($key);

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
The method del() does not exist on Koded\Caching\Client\ShmopClient. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

51
        $this->client->/** @scrutinizer ignore-call */ 
52
                       del($key);

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
The method del() does not exist on Memcached. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

51
        $this->client->/** @scrutinizer ignore-call */ 
52
                       del($key);

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
52 3
        return true;
53
    }
54
55 11
    public function delete(string $key): bool
56
    {
57 11
        if (false === $this->has($key)) {
58 8
            return true;
59
        }
60 8
        return 1 === $this->client->del($key);
61
    }
62
63 80
    public function clear(): bool
64
    {
65 80
        return $this->client->flushDB();
0 ignored issues
show
The method flushDB() does not exist on Memcached. Did you maybe mean flush()? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

65
        return $this->client->/** @scrutinizer ignore-call */ flushDB();

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
The method flushDB() does not exist on Koded\Caching\Client\ShmopClient. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

65
        return $this->client->/** @scrutinizer ignore-call */ flushDB();

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
The method flushDB() does not exist on Koded\Caching\Client\MemoryClient. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

65
        return $this->client->/** @scrutinizer ignore-call */ flushDB();

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
The method flushDB() does not exist on Koded\Caching\Client\FileClient. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

65
        return $this->client->/** @scrutinizer ignore-call */ flushDB();

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
66
    }
67
68 59
    public function has(string $key): bool
69
    {
70 59
        verify_key($key);
71 59
        return (bool)$this->client->exists($key);
0 ignored issues
show
The method exists() does not exist on Koded\Caching\Client\MemoryClient. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

71
        return (bool)$this->client->/** @scrutinizer ignore-call */ exists($key);

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
The method exists() does not exist on Koded\Caching\Client\ShmopClient. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

71
        return (bool)$this->client->/** @scrutinizer ignore-call */ exists($key);

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
The method exists() does not exist on Koded\Caching\Client\FileClient. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

71
        return (bool)$this->client->/** @scrutinizer ignore-call */ exists($key);

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
The method exists() does not exist on Memcached. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

71
        return (bool)$this->client->/** @scrutinizer ignore-call */ exists($key);

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
72
    }
73
}
74