Skip to content

Commit

Permalink
Merge pull request #14 from Traackr/CAMP-976-missing-prefix-child-keys
Browse files Browse the repository at this point in the history
CAMP-976: ensure prefix is attached to child keys
  • Loading branch information
jec3 authored Jan 27, 2021
2 parents 9bcc2ad + 05abe1b commit c5b4d8e
Show file tree
Hide file tree
Showing 2 changed files with 331 additions and 22 deletions.
24 changes: 21 additions & 3 deletions src/RedisTreeEngine.php
Original file line number Diff line number Diff line change
Expand Up @@ -572,6 +572,21 @@ protected function parseMultiKey($key)
return $keys;
}

/**
* Ensure prefix defined in settings is prepended to key.
* @param string $key
* @return string
*/
private function _addKeyPrefix($key)
{
if (!empty($this->settings['prefix'])
&& strpos($key, $this->settings['prefix']) !== 0
) {
$key = $this->settings['prefix'] . $key;
}
return $key;
}

/**
* Get the key used to store the set of child keys.
*
Expand All @@ -582,9 +597,8 @@ protected function parseMultiKey($key)
private function _getChildSetKey($parentKey)
{
$key = $parentKey . $this->_childSetKeySuffix;
if (!empty($this->settings['prefix']) && strpos($key, $this->settings['prefix']) !== 0) {
$key = $this->settings['prefix'] . $key;
}
// ensure prefix is included
$key = $this->_addKeyPrefix($key);
return $key;
}

Expand All @@ -599,6 +613,10 @@ private function _getChildSetKey($parentKey)
private function _writeChildRelationship($parentKey, ...$childKeys)
{
$setKey = $this->_getChildSetKey($parentKey);
// ensure all child keys include prefix
foreach ($childKeys as $index => $key) {
$childKeys[$index] = $this->_addKeyPrefix($key);
}
return $this->redis->sadd($setKey, ...$childKeys);
}

Expand Down
Loading

0 comments on commit c5b4d8e

Please sign in to comment.