1

This is Redis key like "product:1:list:somekey" I want to remove all keys under list key

I used

Redis::del('product:1');

function but it didn't work.

1 Answer 1

2

Redis::keys() method what you need

$keys = Redis::keys('product:1:list:*')

that will return array of keys for given pattern

after that you must prepend your global cache prefix

function addPrefix($keys)
{
    if (!count($keys)) return;

    $prefix = config("cache.prefix") . ":";

    return array_map(function ($item) use ($prefix) {
        return $prefix . $item;
    }, $keys);
}

$prefixed_keys = addPrefix($keys);
Redis::del($prefixed_keys)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.