Repository navigation
feat(PLATECO-2706): decorate predis client #9
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
Closed
Closed
Changes from 3 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
63b2404
Merge pull request #7 from MacPaw/develop
alekseytupichenkov adcf3c7
feat: update schema context bundle
alekseytupichenkov a4c2ab7
Merge pull request #8 from MacPaw/feat/update-core-bundle
alekseytupichenkov c224fad
feat(PLATECO-2706): decorate predis client
serhiidonii 0b0d4f2
feat(PLATECO-2706): decorate predis client
serhiidonii a77ebd1
feat(PLATECO-2706): decorate predis client
serhiidonii 183d0b7
feat(PLATECO-2706): decorate predis client
serhiidonii b8d9be6
Merge remote-tracking branch 'origin/main' into feat/PLATECO-2706-dec…
serhiidonii bd7c66b
feat(PLATECO-2706): decorate predis client
serhiidonii 65ad6aa
feat(PLATECO-2706): decorate predis client
serhiidonii 6cf0ec6
feat(PLATECO-2706): decorate predis client
serhiidonii e989d4d
feat(PLATECO-2706): decorate predis client
serhiidonii File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -7,3 +7,4 @@ | |
| /phpunit.xml | ||
| .phpunit.result.cache | ||
| ###< phpunit/phpunit ### | ||
| /clover.xml | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,113 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| namespace Macpaw\RedisSchemaBundle\Redis; | ||
|
|
||
| use Macpaw\SchemaContextBundle\Service\BaggageSchemaResolver; | ||
| use Predis\Command\CommandInterface; | ||
| use Predis\Command\FactoryInterface; | ||
| use Predis\Configuration\OptionsInterface; | ||
| use Predis\Connection\ConnectionInterface; | ||
| use SymfonyBundles\RedisBundle\Redis\ClientInterface; | ||
|
|
||
| class RedisClientAdapter implements ClientInterface | ||
|
zakhar-huzenko marked this conversation as resolved.
Resolved
|
||
| { | ||
| public function __construct( | ||
| private BaggageSchemaResolver $resolver, | ||
| private ClientInterface $decorated, | ||
| private readonly ?string $defaultSchema = null, | ||
| /** | ||
| * Method names that should be prefixed with the schema which not present in interfaces | ||
| * like a hmget, hset, etc. | ||
| * | ||
| * @var array<string> | ||
| */ | ||
| private readonly array $decoratedCallMethods = [], | ||
| ) { | ||
| } | ||
|
|
||
| public function pop(string $key): ?string | ||
| { | ||
| return $this->decorated->pop($this->prefixKey($key)); | ||
| } | ||
|
|
||
| public function push(string $key, ...$values): int | ||
| { | ||
| return $this->decorated->push($this->prefixKey($key), ...$values); | ||
| } | ||
|
|
||
| public function count(string $key): int | ||
| { | ||
| return $this->decorated->count($this->prefixKey($key)); | ||
| } | ||
|
|
||
| public function remove(string $key): int | ||
| { | ||
| return $this->decorated->remove($this->prefixKey($key)); | ||
| } | ||
|
|
||
| public function getCommandFactory(): FactoryInterface | ||
| { | ||
| return $this->decorated->getCommandFactory(); | ||
| } | ||
|
|
||
| public function getOptions(): OptionsInterface | ||
| { | ||
| return $this->decorated->getOptions(); | ||
| } | ||
|
|
||
| public function connect(): void | ||
| { | ||
| $this->decorated->connect(); | ||
| } | ||
|
|
||
| public function disconnect(): void | ||
| { | ||
| $this->decorated->disconnect(); | ||
| } | ||
|
|
||
| public function getConnection(): ConnectionInterface | ||
| { | ||
| return $this->decorated->getConnection(); | ||
| } | ||
|
|
||
| /** | ||
| * @param array<array-key, mixed> $arguments | ||
| */ | ||
| public function createCommand($method, $arguments = []): CommandInterface | ||
| { | ||
| return $this->decorated->createCommand($method, $arguments); | ||
| } | ||
|
|
||
| public function executeCommand(CommandInterface $command): mixed | ||
| { | ||
| return $this->decorated->executeCommand($command); | ||
| } | ||
|
|
||
| /** | ||
| * @param array<array-key, mixed> $arguments | ||
| */ | ||
| public function __call($method, $arguments): mixed | ||
| { | ||
| if (in_array($method, $this->decoratedCallMethods, true)) { | ||
| // Automatically prefix the first argument if it's a string | ||
| if (array_key_exists(0, $arguments) && is_scalar($arguments[0])) { | ||
| $arguments[0] = $this->prefixKey((string) $arguments[0]); | ||
| } | ||
| } | ||
|
|
||
| return $this->decorated->$method(...$arguments); | ||
| } | ||
|
|
||
| private function prefixKey(string $key): string | ||
| { | ||
| $schema = $this->resolver->getSchema(); | ||
|
|
||
| if ($this->defaultSchema !== null && $schema === $this->defaultSchema) { | ||
| return $key; | ||
| } | ||
|
|
||
| return $schema ? $schema . '.' . $key : $key; | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -17,16 +17,10 @@ class SchemaAwareRedisAdapter implements AdapterInterface, CacheInterface, Reset | |
| public function __construct( | ||
| private readonly RedisAdapter $decorated, | ||
| private readonly BaggageSchemaResolver $resolver, | ||
| private readonly ?string $defaultSchema = null, | ||
| ) { | ||
| } | ||
|
|
||
| private function prefixKey(string $key): string | ||
| { | ||
| $schema = $this->resolver->getSchema(); | ||
|
|
||
| return $schema ? $schema . '.' . $key : $key; | ||
| } | ||
|
|
||
| public function clear(string $prefix = ''): bool | ||
| { | ||
| return $this->decorated->clear($prefix); | ||
|
|
@@ -100,4 +94,15 @@ public function reset(): void | |
| { | ||
| $this->decorated->clear($this->resolver->getSchema() ?? ''); | ||
| } | ||
|
|
||
| private function prefixKey(string $key): string | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Question: if |
||
| { | ||
| $schema = $this->resolver->getSchema(); | ||
|
|
||
| if ($this->defaultSchema !== null && $schema === $this->defaultSchema) { | ||
| return $key; | ||
| } | ||
|
|
||
| return $schema ? $schema . '.' . $key : $key; | ||
| } | ||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.