Skip to content

Commit

Permalink
Merge pull request #4 from asiries335/mvp-4
Browse files Browse the repository at this point in the history
Mvp 4
  • Loading branch information
asiries335 authored Sep 6, 2020
2 parents 3573d15 + 33d0912 commit 0e5a445
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 3 deletions.
18 changes: 15 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,6 @@ listening to a stream as event-loop

## Info

Work with Redis occurs through the package Predis
(https://github.com/nrk/predis)

Need version Redis >= 5.0

## Install
Expand Down Expand Up @@ -73,6 +70,21 @@ $client->stream('test')->add(
);
```

_Find a message by id_

```php

$message = $client->stream('test')->findById('1599404282894-0');

// result.
Asiries335\redisSteamPhp\Data\Message {
-_id: "1599404282894-0"
-_key: "user"
-_body: "{"id":123,"name":"Barney","age":25}"
}

```

_Delete a message_

```php
Expand Down
28 changes: 28 additions & 0 deletions src/Stream.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,34 @@ public function add(string $key, array $values) : string
}
}

/**
* Find a message by id
*
* @param string $id Id Message
*
* @return Message
*
* @throws \Exception
*
*/
public function findById(string $id) : Message
{
$item = $this->_client->call(
Constants::COMMAND_XREAD,
'STREAMS',
$this->_streamName,
$id
);

if (empty($item) === true) {
return new Message;
}

$message = new MessageHydrator();

return $message->hydrate($item[0][1][0], Message::class);
}

/**
* Removes the messages entries from a stream
*
Expand Down

0 comments on commit 0e5a445

Please sign in to comment.