Over a million developers have joined DZone.

Saving Objects In Redis And Php

// A fairly generic method to store arrays and also to add them to a pool to reverse lookup their ids based on values that they contain. This method extends my own redis client but will work for the better clients out there such as predis.

class storage extends redis {

  public function save($key, array $object, $timestamp=true){
    $timestamp && $object['timestamp'] = date('Ymdhis');
    $id = $this->incr('id:'.$key);
    foreach ($object as $k => $v) {
      $this->sadd(sprintf("%s:%s:%s", $key, $k, $v), $id);

    $key = sprintf("%s:%s", $key, $id);
    $this->hmset($key, $object);

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}