src/Traits/SupportRedis.php
public function getElseSet(string $key, int $ttl, callable $callable)
    {
        if ($this->exists($key)) {
            return $this->get($key);
        }

        try {
            $callable_data = call_user_func($callable);
        } catch( Exception $e ) {
            // throw exception
        }

        $this->set($key, $callable_data);
        $this->expireAt($key, time() + $ttl);

        return $this->get($key);
    }
public function getElseSet(string $key, int $ttl, callable $callable)
    {
        if ($this->exists($key)) {
            return $this->get($key);
        }

        try {
            $callable_data = call_user_func($callable);
        } catch( Exception $e ) {
            // throw exception
        }

        $this->set($key, $callable_data);
        $this->expireAt($key, time() + $ttl);

        return $this->get($key);
    }
public function getElseSet ( string $ key , int $ ttl , callable $ callable ) { if ( $ this -> exists ( $ key ) ) { return $ this -> get ( $ key ) ; } try { $ callable_data = call_user_func ( $ callable ) ; } catch ( Exception $ e ) { // throw exception } $ this -> set ( $ key , $ callable_data ) ; $ this -> expireAt ( $ key , time ( ) + $ ttl ) ; return $ this -> get ( $ key ) ; }
Get the cache key. If it does not exist, execute the callable and set the cache key.

@param   string      $key
@param   int         $ttl
@param   callable    $callable
@return  mixed
Get the cache key . If it does not exist execute the callable and set the cache key .