Follow me on twitter…

Extending Rediska

You can add, delete or replace commands without creating your own class with command manager:


// Initialize Rediska
$rediska = new Rediska();

// Add command with name 'myCommand'
Rediska_Commands::add('myCommand', 'MyCommandClass');

// Execute you command

// Remove you command


Rediska command internally is a class implementing Rediska_Command_Interface:


interface Rediska_Command_Interface
    public function __construct(Rediska $rediska, $name, $arguments = array());
    public function write();
    public function read();
    public function execute();
    public function isAtomic();
    public function isQueued();


If you need your own custom command, best choice is to use abstract class Rediska_Command_Abstract, which implements all basic functionality and allows you to add some custom logic:


class MyCommandClass extends Rediska_Command_Abstract
  // This method called when command initialized
  public function create($name)
    $namespace = $this->getRediska()

    $command = array('GET',
                     $namespace . $name);

    $connection = $this->getRediska()

    // You may return array of execs
    return new Rediska_Connection_Exec($connection, $command);

  // This method called after reading response from connection
  public function parseResponse($response)
    $value = $this->getRediska()
    // You may get command argument through object property
    return $this->name . ': ' .  $value;



Fork me on GitHub