Welcome Guest, Not a member yet? Register   Sign In
Add new functions to Redis Handler
#1

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...asses.html but i have to admit that i don't fully understand how it work.

Can anyone describe me how i can do please ?
Reply
#2

(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...asses.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!
Reply
#3

Hello Tgix and Thank you, it works ! Smile
Reply
#4

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

Glad to hear, Happy coding!
Reply




Theme © iAndrew 2016 - Forum software by © MyBB