RobiNN1 / phpCacheAdmin

A web dashboard for your favorite caching system.
MIT License
302 stars 11 forks source link

Redis: gz decode key/item #9

Closed VIS89 closed 2 years ago

VIS89 commented 2 years ago

Hello, We faced an issue viewing the key where the info is gunzipped/encoded. Would be very nice if you support some decompress/decode methods by default. I see some desktop software support that. Uploading an example. If you like I can also upload the redis key. Just for your information, that's a stored key from Magento 2.4 redis backend cache. image

RobiNN1 commented 2 years ago

I know, currently it just shows a plain unformatted value. This is definitely something that needs to be improved.

VIS89 commented 2 years ago

gzipkey.txt Here's the key in txt format. Thanks for a great job!

VIS89 commented 2 years ago

Hey, sorry to reopen the task. Just tested it, here's the result. image

RobiNN1 commented 2 years ago

What the heck is this compression lol. I tried the standard gzcompress(), gzencode(), gzdeflate() and these work fine.

I need to check Magento source code. If this is from it.

VIS89 commented 2 years ago

I can help you if you need more info, just let me know. You can write me here or email me.

RobiNN1 commented 2 years ago

Got it, Magento uses this library https://github.com/colinmollenhour/Cm_Cache_Backend_Redis

And here is code for decoding https://github.com/colinmollenhour/Cm_Cache_Backend_Redis/blob/master/Cm/Cache/Backend/Redis.php#L1315

It uses standard gzuncompress() as well but with prefix..

RobiNN1 commented 2 years ago

Small update:

I don't want any system-specific codes in this app, so add this into 'encoding' => [] section in your config.php file

'gz_magento' => [
    'view' => static function (string $value): ?string {
        // https://github.com/colinmollenhour/Cm_Cache_Backend_Redis/blob/master/Cm/Cache/Backend/Redis.php#L1306-L1323
        if (strpos($value, "gz:\x1f\x8b") === 0) {
            $value = substr($value, 5);
        }

        return @gzuncompress($value) !== false ? gzuncompress($value) : null;
    },
    'save' => static fn (string $value): string => "gz:\x1f\x8b".gzcompress($value),
],

The reason is simple, app now allows people to add their own encoding/decoding functions, so there's no reason to have it there by default. Also not everyone uses Magento.