Skip to content

Commit

Permalink
Merge pull request BedrockStreaming#64 from aburakovskiy/master
Browse files Browse the repository at this point in the history
Add support for SUNION and SINTER commands
  • Loading branch information
omansour authored Jan 15, 2018
2 parents ab0ae6b + 31a379b commit 904ea81
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ Redis command | Description
**SADD** *key* *member* *[member ...]* | Adds one or more members to a set
**SISMEMBER** *key* *member* | Determines if a member is in a set
**SMEMBERS** *key* | Gets all the members in a set
**SUNION** *key* *[key ...]* | Returns the members of the set resulting from the union of all the given sets.
**SINTER** *key* *[key ...]* | Returns the members of the set resulting from the intersection of all the given sets.
**SCARD** *key* | Get cardinality of set (count of members)
**SREM** *key* *member* *[member ...]* | Removes one or more members from a set
**HDEL** *key* *field* | Delete one hash fields
Expand Down
29 changes: 29 additions & 0 deletions src/M6Web/Component/RedisMock/RedisMock.php
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,35 @@ public function smembers($key)
return $this->returnPipedInfo(self::$dataValues[$this->storage][$key]);
}

public function sunion($key)
{
$this->stopPipeline();
$keys = is_array($key) ? $key : func_get_args();
$result = [];
foreach ($keys as $key) {
$result = array_merge($result, $this->smembers($key));
}
$result = array_values(array_unique($result));

$this->restorePipeline();

return $this->returnPipedInfo($result);
}

public function sinter($key)
{
$this->stopPipeline();
$keys = is_array($key) ? $key : func_get_args();
$result = [];
foreach ($keys as $key) {
$result[] = $this->smembers($key);
}
$result = call_user_func_array('array_intersect', $result);

$this->restorePipeline();

return $this->returnPipedInfo($result);
}

public function scard($key)
{
Expand Down

0 comments on commit 904ea81

Please sign in to comment.