简体   繁体   中英

Prefix only redis session keys

Is there a way to use one Predis client connection throughout an application but only prefix the session keys?

The Predis library only allows a key prefix to be defined by setting the options parameter when instantiating a client object :

$sessionClient = new Predis\Client($config, array('prefix' => 'session-'));

I'm storing more than just sessions in one Redis instance. So to store other values without the prefix I would think this would work:

$client = new Predis\Client($config);

But keys are still being prefixed. I assume Predis is sharing the connection and options across client instances. So how can one prefix just the session keys?

Found a related issue on Github with a response from the author that this won't be supported.

Predis\\Session\\SessionHandler accepts a client instance only for the sake of injection, but you shouldn't really reuse that client for anything else... Obviously, for very specific scenarios nothing stops you from writing your own session handler.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM