Skip to content

Commit

Permalink
Merge pull request #88 from clementtalleu/fix/client_nullable_manager
Browse files Browse the repository at this point in the history
fix object manager
  • Loading branch information
clementtalleu authored Sep 22, 2024
2 parents 4fd4375 + d0b59d3 commit c722233
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 5 deletions.
3 changes: 2 additions & 1 deletion docs/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ php-redis-om provide a way to use persistent connections with the `RedisClient`

```php
// Set the persistent connection to true
$objectManager = new RedisObjectManager(createPersistentConnection: true);
$objectManager = new RedisObjectManager();
$bjectManager->getRedisClient()->createPersistentConnection();

// Then you can use the ObjectManager normally
$objectManager->persist($user);
Expand Down
1 change: 0 additions & 1 deletion src/Client/PredisClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ public function createPersistentConnection(?string $host = null, ?int $port = nu
'persistent' => true,
'timeout' => $timeout,
]);
;
}

/**
Expand Down
3 changes: 2 additions & 1 deletion src/Om/Persister/AbstractPersister.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace Talleu\RedisOm\Om\Persister;

use Talleu\RedisOm\Client\PredisClient;
use Talleu\RedisOm\Client\RedisClient;
use Talleu\RedisOm\Client\RedisClientInterface;
use Talleu\RedisOm\Om\Key\KeyGenerator;
Expand All @@ -15,7 +16,7 @@ public function __construct(
private ?KeyGenerator $keyGenerator = null,
protected ?RedisClientInterface $redis = null
) {
$this->redis = $redis ?? (new RedisClient());
$this->redis = $redis ?? getenv('REDIS_CLIENT') === 'predis' ? new PredisClient() : new RedisClient();

$this->keyGenerator = $keyGenerator ?? new KeyGenerator();
}
Expand Down
11 changes: 9 additions & 2 deletions src/Om/RedisObjectManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

namespace Talleu\RedisOm\Om;

use Talleu\RedisOm\Client\PredisClient;
use Talleu\RedisOm\Client\RedisClient;
use Talleu\RedisOm\Client\RedisClientInterface;
use Talleu\RedisOm\Om\Converters\HashModel\HashObjectConverter;
use Talleu\RedisOm\Om\Converters\JsonModel\JsonObjectConverter;
Expand All @@ -27,8 +29,10 @@ final class RedisObjectManager implements RedisObjectManagerInterface
protected ?KeyGenerator $keyGenerator = null;

public function __construct(
private readonly ?RedisClientInterface $redisClient,
private ?RedisClientInterface $redisClient = null,
) {
$this->redisClient = getenv('REDIS_CLIENT') === 'predis' ? new PredisClient() : new RedisClient();

$this->keyGenerator = new KeyGenerator();
}

Expand Down Expand Up @@ -213,5 +217,8 @@ public function dropIndex(object $object, string $fqcn = null): void
$this->redisClient->dropIndex($object->prefix ?? $fqcn);
}


public function getRedisClient(): ?RedisClientInterface
{
return $this->redisClient;
}
}

0 comments on commit c722233

Please sign in to comment.