CodeIgniter Forums
Add new functions to Redis Handler - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: CodeIgniter 4 (https://forum.codeigniter.com/forumdisplay.php?fid=28)
+--- Forum: CodeIgniter 4 Support (https://forum.codeigniter.com/forumdisplay.php?fid=30)
+--- Thread: Add new functions to Redis Handler (/showthread.php?tid=78670)



Add new functions to Redis Handler - eelisland - 02-23-2021

What is the proper way to add thoses function to the Redis Handler whithout writing it in the System\Cache\Handlers\RedisHandler.php file ?

PHP Code:
    public function getKeysstring $keys "*" )
    {
        return 
$this->redis->keys($keys);
    }

    
//--------------------------------------------------------------------
    
    
public function delWildcardstring $keys )
    {
        if (!
$keys || $keys === "*") return false;
        
        
$this->redis->del(
            
$this->redis->keys($keys)
        );
    } 

I read this from the Documentation here https://codeigniter4.github.io/userguide/extending/core_classes.html but i have to admit that i don't fully understand how it work.

Can anyone describe me how i can do please ?


RE: Add new functions to Redis Handler - tgix - 02-23-2021

(02-23-2021, 10:03 AM)eelisland Wrote: What is the proper way to add thoses function to the Redis Handler whithout writing it in the System\Cache\Handlers\RedisHandler.php file ?

PHP Code:
    public function getKeysstring $keys "*" )
    {
        return 
$this->redis->keys($keys);
    }

    
//--------------------------------------------------------------------
    
    
public function delWildcardstring $keys )
    {
        if (!
$keys || $keys === "*") return false;
        
        
$this->redis->del(
            
$this->redis->keys($keys)
        );
    } 

I read this from the Documentation here https://codeigniter4.github.io/userguide/extending/core_classes.html but i have to admit that i don't fully understand how it work.

Can anyone describe me how i can do please ?

Rule #1: don't mess with framework files!
I had to work around an issue in Redis handler by creating my own RedisHandler in app/Libraries:
PHP Code:
<?php


namespace App\Libraries;


class 
FixedRedisHandler extends \CodeIgniter\Cache\Handlers\RedisHandler
{
// code fixing save() function in 4.0.4


In app/Config/Cache.php I added this to the array of validHandlers:
PHP Code:
    public $validHandlers = [
        'dummy' => \CodeIgniter\Cache\Handlers\DummyHandler::class,
        'file' => \CodeIgniter\Cache\Handlers\FileHandler::class,
        'memcached' => \CodeIgniter\Cache\Handlers\MemcachedHandler::class,
        'predis' => \CodeIgniter\Cache\Handlers\PredisHandler::class,
        'redis' => \CodeIgniter\Cache\Handlers\RedisHandler::class,
        'fixedredis' => FixedRedisHandler::class,
        'wincache' => \CodeIgniter\Cache\Handlers\WincacheHandler::class,
    ]; 
And finally set the handler in app/Config/Cache.php to "fixedredis".
Hope this helps!


RE: Add new functions to Redis Handler - eelisland - 02-24-2021

Hello Tgix and Thank you, it works ! Smile


RE: Add new functions to Redis Handler - tgix - 02-24-2021

(02-24-2021, 02:11 AM)eelisland Wrote: Hello Tgix and Thank you, it works ! Smile

Glad to hear, Happy coding!