Skip to content

feat: dynamic storage name#2

Open
slowmove wants to merge 2 commits intomainfrom
feat/dynamic-storage-name
Open

feat: dynamic storage name#2
slowmove wants to merge 2 commits intomainfrom
feat/dynamic-storage-name

Conversation

@slowmove
Copy link
Owner

No description provided.

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds support for naming queues (storageName) across storage adapters, enabling multiple queues to share the same backing storage directory/connection while using distinct file names / keys / tube names.

Changes:

  • Extended Queue and StorageFactory APIs to accept storageName (defaulting to queue).
  • Updated storage adapters (File/Sqlite/Redis/Beanstalkd) to incorporate the provided name in their backing store identifier.
  • Added Pest tests for File and Sqlite adapters, plus updated examples to demonstrate storageName.

Reviewed changes

Copilot reviewed 10 out of 10 changed files in this pull request and generated 7 comments.

Show a summary per file
File Description
tests/SqliteStorageTest.php Adds Sqlite adapter behavior tests (file creation + FIFO semantics).
tests/FileStorageTest.php Adds File adapter behavior tests (file creation + FIFO semantics).
src/Storage/StorageFactory.php Passes storageName through when instantiating adapters.
src/Storage/Adapters/SqliteStorage.php Uses storageName to build the .db filename when given a directory.
src/Storage/Adapters/RedisStorage.php Uses a configurable Redis list key (storageKey) instead of a hardcoded default.
src/Storage/Adapters/FileStorage.php Uses storageName to build the .txt filename when given a directory; removes debug output.
src/Storage/Adapters/BeanstalkdStorage.php Uses a configurable tube name; refactors connection string parsing inputs.
src/Queue.php Updates constructor to accept storagePath + storageName; removes debug output; adjusts exist() return type.
examples/producer.php Updates example to new constructor args and demonstrates storageName.
examples/consumer.php Updates example to new constructor args and demonstrates storageName.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

You can also share your feedback on Copilot code review. Take the survey.

StorageType::BEANSTALKD => new BeanstalkdStorage($storagePath),
StorageType::FILE => new FileStorage($storagePath, $storageName),
StorageType::SQLITE => new SqliteStorage($storagePath, $storageName),
StorageType::REDIS => new RedisStorage($storagePath, $storageName),
public function __construct(
string $connectionString = self::DEFAULT_STORAGE_PATH,
string $storageKey = 'queue'
) {
{
$exist = $this->redisClient->executeRaw(["LPOS", self::DEFAULT_STORAGE_NAME, $value]);
$exist = $this->redisClient->executeRaw(["LPOS", $this->storageKey, $value]);
return boolval($exist);
Comment on lines +26 to +30
if ($connectionString && strpos($connectionString, ":") > -1) {
$connectionStringParts = explode(':', $connectionString);
$host = $connectionStringParts[0];
$port = $connectionStringParts[1];
} else if ($connectionString) {
}

public function exist($value): ?string
public function exist($value): bool
Comment on lines +40 to +44
it('creates a queue file when initialized with a directory path', function () {
new FileStorage($this->tempDir);

expect(is_file($this->tempDir . DIRECTORY_SEPARATOR . 'queue.txt'))->toBeTrue();
});
Comment on lines +40 to +44
it('creates a sqlite database file when initialized with a directory path', function () {
new SqliteStorage($this->tempDir);

expect(is_file($this->tempDir . DIRECTORY_SEPARATOR . 'queue.db'))->toBeTrue();
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants