Extending Rediska
You can add, delete or replace commands without creating your own class with static methods:
<?php /** * Add command * * @param string $name Command name * @param string $className Name of class */ public static function addCommand($name, $className) /** * Remove command * * @param string $name Command name */ public static function removeCommand($name) ?>
Rediska command internally is a class implementing Rediska_Command_Interface:
<?php interface Rediska_Command_Interface { public function __construct(Rediska $rediska, $name, $arguments); public function write(); public function read(); public function isAtomic(); } ?>
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:
<?php require_once 'Rediska/Command/Abstract.php'; class MyGetCommand extends Rediska_Command_Abstract { // This method called when command initialized protected function _create($name) { $command = "GET {$this->_rediska->getOption('namespace')}$name"; $connection = $this->_rediska->getConnectionByKeyName($name); // Add command with specified connection to buffer // You may add many commands to many connections $this->_addCommandByConnection($connection, $command); } // This method called after reading response from connection // $response array of answers to commands added with addCommandByConnection keeping order protected function _parseResponse($response) { $value = $this->_rediska->unserialize($response[0]); // You may get command argument через свойство $this->argumentName return $this->name . ': ' . $value; } } ?>