nrk/predis — Issue #58: Ugly code when using pipleline
Author: hadees
Created: 2012-01-26 23:51:18+00:00
State: open

This really isn't an issue with predis but i'm looking for some direction on how I can abstract this code more and not make it look so ugly. The self thing is because of 5.3. Maybe you could put some more complex examples in the wiki?

```
function increment($field, $increment=1) {
$self = &$this;
$replies = $this->redis->pipeline(function($pipe) use(&$self, &$increment) {
$pipe->hincrby($self->dailyKey(), $field, $increment);
$pipe->hincrby($self->monthlyKey(), $field, $increment);
$pipe->hincrby($self->totalKey(), $field, $increment);
});
$this->daily->$$field = $replies[0];
$this->monthly->$$field = $replies[1];
$this->total->$$field = $replies[2];
}

function serverSync() {
$self = &$this;
$replies = $this->redis->pipeline(function($pipe) use(&$self) {
$pipe->hgetall($self->dailyKey());
$pipe->hgetall($self->monthlyKey());
$pipe->hgetall($self->totalKey());
});
}
```