using redis for replacing zPush Kolab cache

Bogomil Shopov shopov at kolabsys.com
Tue Nov 30 13:53:40 CET 2010


Hey Alain,
 Ijust wrote a test class for replacing userCache class at kolab.php backend:

<?php

//require Rediska package (/kolab/lib/php)
require_once 'Rediska.php';

//create a class that emulates the existing class UserCache
$c=new ReuserCache();
//call open method
$c->open('test at lelemale_IMEI123');

//write (key/Value)
$c->write("ACTIVESYNCFID:INBOX/Calendar40", 
"a337577a583221724b8ebddbee1457905a73be7955");

//find the value for the $key
$c->find('ACTIVESYNCFID:INBOX/Calendar40');



class ReuserCache 
{
    public $options;
    public $cacher;
    public $keystorage;
    public $zkey;
    
    
    function __construct()
    {
     $this->options = array(
     'namespace' => 'bCache_',
     'name'      => 'bcache');
     //initiate default (without options)
     $this->cacher = new Rediska();

    }
    
    
    function open($zkey)
    {
        //just set the key variable. We will use it later for $zkey.":".$key 
(see write)
       $this->zkey=$zkey;
       
    }
    
    function close()
    {
        
    }
    function write($key, $value)
    {
        //Create a new instance in order to work with Redis Key
        $this->keystorage=new Rediska_Key($this->zkey.":".$key);
       
        //if key exists, skip it
       if($this->keystorage->getValue($this->zkey.":".$key)) {
        // do something
       }
       else
       {
           $this->keystorage->setValue($value);
       }
    }
    function delete()
    {
        
    }
    function purge()
    {
        
    }
    function find($what)
    {
        echo $this->keystorage->getValue($this->zkey.":".$what);
    }
    
    
}
?>

//Bogo




More information about the users mailing list