diff --git a/README.md b/README.md index ed0bab4..328a69a 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/src/M6Web/Component/RedisMock/RedisMock.php b/src/M6Web/Component/RedisMock/RedisMock.php index f392016..0dd8e00 100644 --- a/src/M6Web/Component/RedisMock/RedisMock.php +++ b/src/M6Web/Component/RedisMock/RedisMock.php @@ -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) {