Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introduce StorageRedisDsnModule #144

Merged
merged 41 commits into from
Nov 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
001fa13
Add Redis DSN module and provider
koriym Sep 3, 2024
856220b
Rename and deprecate StorageRedisModule
koriym Sep 3, 2024
b38898c
Add Memcached EtagPool module and unit test
koriym Sep 3, 2024
3abfa15
Implement ProviderInterface with type annotations
koriym Sep 3, 2024
a86d295
Remove incorrect doc comment from constructor parameter
koriym Sep 3, 2024
9b00efd
Add support for Redis DSN options
koriym Sep 4, 2024
f7db236
Document psalm suppression for Relay class
koriym Sep 4, 2024
b8be72c
Refactor ResourceStorage with ProviderInterface
koriym Sep 5, 2024
17355d9
[tmp] Update ray/di dependency to dev-provider-serialisable
koriym Sep 7, 2024
02d9f80
Refactor method param type to reusable annotation
koriym Sep 7, 2024
6dd11e8
Suppress unused parameter warnings in NullTagAwareAdapter
koriym Sep 7, 2024
4e0d067
Fix typo in psalm-suppress annotation
koriym Sep 7, 2024
3862011
Add @codeCoverageIgnore annotation to NullTagAwareAdapter
koriym Sep 7, 2024
b1b6d86
Suppress UndefinedClass error in RedisDsnProvider
koriym Sep 10, 2024
6bbdfa5
fixup! Fix typo in psalm-suppress annotation
koriym Sep 10, 2024
9f1a0de
Change type hints for method parameters
koriym Sep 10, 2024
5b8d357
Update ray/aop dependency to ^2.16
koriym Sep 10, 2024
fb214bf
fixup! Change type hints for method parameters
koriym Sep 10, 2024
12d7cfe
Remove NullTagAwareAdapter and update bindings
koriym Sep 10, 2024
f5bb378
Ignore major updates for phpunit/phpunit
koriym Sep 10, 2024
b204b81
Add TagsPool annotation class
koriym Sep 10, 2024
45fc57e
Add TagsPool binding to QueryRepositoryModule
koriym Sep 10, 2024
3c1f263
Remove ApcuAdapter binding from Redis DSN module
koriym Sep 10, 2024
c33e98a
Add deprecated ResourceStorageCacheableTrait
koriym Sep 10, 2024
f63b59e
Add deprecated ResourceStorageCacheableTrait
koriym Sep 10, 2024
07096b9
fixup! Add deprecated ResourceStorageCacheableTrait
koriym Sep 10, 2024
715289a
Mark NamespacedCacheProvider class as deprecated
koriym Sep 10, 2024
69f49f1
Mark BcModule as deprecated
koriym Sep 10, 2024
065d227
Rename and deprecate StorageRedisMemcachedModule
koriym Sep 10, 2024
17c4257
Rename and deprecate StorageRedisModuleTest
koriym Sep 10, 2024
552d7bd
Deprecate StorageApcModuleTest
koriym Sep 10, 2024
ac8dc1e
Remove shared cache item pool binding
koriym Sep 10, 2024
2b6b17b
Remove unused PSR cache annotations and RedisAdapter binding
koriym Sep 10, 2024
980b5c4
Enhance Memcached module with TagAwareAdapter support
koriym Sep 10, 2024
197cc3b
Update ray/di dependency version in composer.json
koriym Sep 10, 2024
35244e7
Remove unused MemcachedAdapter bindings
koriym Sep 10, 2024
00543f5
Add local cache binding for ResourceObjectPool
koriym Sep 10, 2024
6a42ff8
Capitalize comment for consistency
koriym Sep 10, 2024
2f1c0b1
Add test for invalid server string in Memcached Etag Module
koriym Nov 1, 2024
df7d1cd
Fix typo in deprecated notice
koriym Nov 1, 2024
d67eeb7
Update tests-pecl-ext/StorageRedisDsnModuleTest.php
koriym Nov 1, 2024
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
2 changes: 2 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,5 @@ updates:
ignore:
- dependency-name: "*" # Ignore all dependencies for specific update types
update-types: ["version-update:semver-minor", "version-update:semver-patch"]
- dependency-name: "phpunit/phpunit"
update-types: ["version-update:semver-major"]
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
"doctrine/cache": "^1.12 || ^2.0",
"mobiledetect/mobiledetectlib": "^3.74",
"psr/cache": "^1.0 || ^2.0 || ^3.0",
"ray/aop": "^2.10",
"ray/di": "^2.13.1",
"ray/aop": "^2.16",
"ray/di": "^2.17.2",
"ray/psr-cache-module": "^1.3.4",
"symfony/cache": "^5.3 || ^6.0",
"symfony/cache-contracts": "^2.4 || ^3.0"
Expand Down
7 changes: 7 additions & 0 deletions psalm.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,11 @@
<directory name="vendor" />
</ignoreFiles>
</projectFiles>
<issueHandlers>
<UndefinedClass>
<errorLevel type="suppress">
<file name="src/RedisDsnProvider.php" />
</errorLevel>
</UndefinedClass>
</issueHandlers>
</psalm>
12 changes: 1 addition & 11 deletions src-annotation/EtagPool.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,10 @@
namespace BEAR\RepositoryModule\Annotation;

use Attribute;
use Doctrine\Common\Annotations\Annotation\NamedArgumentConstructor;
use Ray\Di\Di\Qualifier;

/**
* @Annotation
* @Qualifier
* @NamedArgumentConstructor
*/
#[Attribute(Attribute::TARGET_PARAMETER | Attribute::TARGET_METHOD)]
#[Attribute(Attribute::TARGET_PARAMETER)]
#[Qualifier]
final class EtagPool
{
public function __construct(
public string $value = '',
) {
}
}
14 changes: 14 additions & 0 deletions src-annotation/RedisDsn.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php

declare(strict_types=1);

namespace BEAR\RepositoryModule\Annotation;

use Attribute;
use Ray\Di\Di\Qualifier;

#[Attribute(Attribute::TARGET_PARAMETER)]
#[Qualifier]
final class RedisDsn
{
}
14 changes: 14 additions & 0 deletions src-annotation/RedisDsnOptions.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php

declare(strict_types=1);

namespace BEAR\RepositoryModule\Annotation;

use Attribute;
use Ray\Di\Di\Qualifier;

#[Attribute(Attribute::TARGET_PARAMETER)]
#[Qualifier]
final class RedisDsnOptions
{
}
14 changes: 14 additions & 0 deletions src-annotation/ResourceObjectPool.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php

declare(strict_types=1);

namespace BEAR\RepositoryModule\Annotation;

use Attribute;
use Ray\Di\Di\Qualifier;

#[Attribute(Attribute::TARGET_PARAMETER)]
#[Qualifier]
final class ResourceObjectPool
{
}
14 changes: 14 additions & 0 deletions src-annotation/TagsPool.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php

declare(strict_types=1);

namespace BEAR\RepositoryModule\Annotation;

use Attribute;
use Ray\Di\Di\Qualifier;

#[Attribute(Attribute::TARGET_PARAMETER)]
#[Qualifier]
final class TagsPool
{
}
2 changes: 2 additions & 0 deletions src-deprecated/BcModule.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
use Ray\Di\Scope;

/**
* @deprecated
*
* Backward Compatibility module
*
* Install this when you need deprecated interface.
Expand Down
5 changes: 3 additions & 2 deletions src-deprecated/NamespacedCacheProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,15 @@
use Doctrine\Common\Cache\CacheProvider;
use Ray\Di\ProviderInterface;

/**
* @deprecated
*/
class NamespacedCacheProvider implements ProviderInterface
{
/** @var CacheProvider */
private $cache;

/**
* @deprecated
*
* @CacheEngine("cache")
* @AppName("appName")
* @CacheVersion("version")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@

use function assert;

/**
* @deprecated
*/
koriym marked this conversation as resolved.
Show resolved Hide resolved
trait ResourceStorageCacheableTrait
{
koriym marked this conversation as resolved.
Show resolved Hide resolved
/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,12 @@
use Ray\PsrCacheModule\MemcachedAdapter;
use Ray\PsrCacheModule\MemcachedProvider;
use Ray\PsrCacheModule\Psr6RedisModule;

use function array_map;
use function explode;

/**
* @deprecated
*
* Bind redis to shared storage, Bind memcache to etag pool
*/
final class StorageRedisMemcachedModule extends AbstractModule
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
* The following module are installed:
*
* Psr6RedisModule
*
* @deprecated Use StorageRedisDsnModule instead
*/
final class StorageRedisModule extends AbstractModule
{
Expand Down
7 changes: 6 additions & 1 deletion src/ProdQueryRepositoryModule.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@
namespace BEAR\QueryRepository;

use BEAR\RepositoryModule\Annotation\KnownTagTtl;
use BEAR\RepositoryModule\Annotation\ResourceObjectPool;
use Ray\Di\AbstractModule;
use Ray\PsrCacheModule\LocalCacheProvider;
use Symfony\Component\Cache\Adapter\AdapterInterface;

final class ProdQueryRepositoryModule extends AbstractModule
{
Expand All @@ -16,7 +19,9 @@ final class ProdQueryRepositoryModule extends AbstractModule
*/
protected function configure(): void
{
// boost the performance of symfony/cache
// Bind ResourceObjectPool to local cache (APCu or File)
$this->bind(AdapterInterface::class)->annotatedWith(ResourceObjectPool::class)->toProvider(LocalCacheProvider::class);
// Boost the performance of symfony/cache
$this->bind()->annotatedWith(KnownTagTtl::class)->toInstance(0.15);
}
}
26 changes: 20 additions & 6 deletions src/QueryRepositoryModule.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,22 @@
namespace BEAR\QueryRepository;

use BEAR\RepositoryModule\Annotation\EtagPool;
use BEAR\RepositoryModule\Annotation\ResourceObjectPool;
use BEAR\RepositoryModule\Annotation\TagsPool;
use BEAR\Resource\NamedParameter;
use BEAR\Resource\NamedParameterInterface;
use Psr\Cache\CacheItemPoolInterface;
use Ray\Di\AbstractModule;
use Ray\Di\Scope;
use Ray\PsrCacheModule\Annotation\Shared;
use Symfony\Component\Cache\Adapter\AdapterInterface;
use Symfony\Component\Cache\Adapter\NullAdapter;
use Symfony\Component\Cache\Adapter\TagAwareAdapter;
use Symfony\Component\Cache\Adapter\TagAwareAdapterInterface;

/**
* Provides ResourceStorageInterface and derived bindings
*
* The following bindings are provided:
*
* CacheItemPoolInterface-Shared::class
* CacheItemPoolInterface-EtagPool::class
* QueryRepositoryInterface
* CacheDependencyInterface
Expand All @@ -41,9 +43,20 @@ final class QueryRepositoryModule extends AbstractModule
*/
protected function configure(): void
{
// Null cache default
$this->bind(CacheItemPoolInterface::class)->annotatedWith(Shared::class)->to(NullAdapter::class)->in(Scope::SINGLETON);
$this->bind(CacheItemPoolInterface::class)->annotatedWith(EtagPool::class)->toInstance(null);
// Null cache engine default
$this->bind(AdapterInterface::class)->annotatedWith(ResourceObjectPool::class)->to(NullAdapter::class);
// When null is bound, the same adapter as the one assigned to the ResourceObjectPool is used.
$this->bind(AdapterInterface::class)->annotatedWith(TagsPool::class)->toInstance(null);
// TagAwareAdapterInterface is injected into ResourceStorage
$this->bind(TagAwareAdapterInterface::class)->annotatedWith(ResourceObjectPool::class)->toConstructor(
TagAwareAdapter::class,
[
'itemsPool' => ResourceObjectPool::class,
'tagsPool' => TagsPool::class,
],
)->in(Scope::SINGLETON);
// When null is bound, the same adapter as the one assigned to the ResourceObjectPool is used.
$this->bind(TagAwareAdapterInterface::class)->annotatedWith(EtagPool::class)->toInstance(null);
// core
$this->bind(QueryRepositoryInterface::class)->to(QueryRepository::class)->in(Scope::SINGLETON);
$this->bind(CacheDependencyInterface::class)->to(CacheDependency::class);
Expand All @@ -53,6 +66,7 @@ protected function configure(): void
$this->bind(MatchQueryInterface::class)->to(MatchQuery::class)->in(Scope::SINGLETON);
$this->bind(UriTag::class)->in(Scope::SINGLETON);
$this->bind(RefreshAnnotatedCommand::class);
$this->bind(ResourceStorageSaver::class);
// #[Cacheable]
$this->install(new CacheableModule());
// #[CacheableResponse]
Expand Down
36 changes: 36 additions & 0 deletions src/RedisDsnProvider.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php

declare(strict_types=1);

namespace BEAR\QueryRepository;

use BEAR\RepositoryModule\Annotation\RedisDsn;
use BEAR\RepositoryModule\Annotation\RedisDsnOptions;
use Predis\ClientInterface;
use Ray\Di\ProviderInterface;
use Redis;
use RedisArray;
use RedisCluster;
use Relay\Relay;
use Symfony\Component\Cache\Adapter\RedisAdapter;

/** @implements ProviderInterface<Redis|RedisArray|RedisCluster|ClientInterface|Relay> */
final class RedisDsnProvider implements ProviderInterface
{
/**
* @param string $dns Redis DSN
* @param array<string, bool|int|string|array<string, mixed>|null> $options Redis DSN Options
*/
public function __construct(
#[RedisDsn]
private string $dns,
#[RedisDsnOptions]
private array $options,
) {
}

public function get(): Redis|RedisArray|RedisCluster|ClientInterface|Relay
{
return RedisAdapter::createConnection($this->dns, $this->options);
}
koriym marked this conversation as resolved.
Show resolved Hide resolved
}
Loading
Loading