Rediska

Follow me on twitter…

Zend_Cache backend

Redis is a nice solution for caching your data.

Rediska provides Redis adapter for Zend_Cache.

<?php

// About initialize and working with Zend_Cache
// read offical Zend_Cache manual:
// http://framework.zend.com/manual/en/zend.cache.html

// Core frontend options
$frontendOptions = array(
    'cache_id_prefix'         => 'Application_',
    'automatic_serialization' => true
);
// Redis backend options
$backendOptions = array(
    // rediska - Rediska instance name, Rediska object or Rediska options for new instance. Default instance if not specified.
    'rediska' => new Rediska(),
);

$cache = Zend_Cache::factory(
    'Core',
    'Rediska_Zend_Cache_Backend_Redis',
    $frontendOptions,
    $backendOptions,
    false,
    true
);

$data = array(1, 2, 3);
$cache->save($data, 'data');

?>

Comments

Nauw October 18, 2010 21:50

Good morning,

Thanks for implementing your library for Zend.

I just tested the code above, and it seems that the Cache need serialize information.(error is thrown)

I just put to make the sample works
$data = serialize(array(1, 2, 3));

And it's working fine.

Regards,

Arnaud

Ivan Shumkov October 20, 2010 17:59

I fix it, thanks!

wormhit April 04, 2012 07:12

I'm using ZF ver 1.11.11

$cache = Zend_Cache::factory(
'core',
new Rediska_Zend_Cache_Backend_Redis(),
$frontendOptions,
$backendOptions
);

Fork me on GitHub