简体   繁体   English

仅前缀redis会话密钥

[英]Prefix only redis session keys

Is there a way to use one Predis client connection throughout an application but only prefix the session keys? 有没有办法在整个应用程序中使用一个Predis客户端连接,但只有会话密钥的前缀?

The Predis library only allows a key prefix to be defined by setting the options parameter when instantiating a client object : Predis库只允许在实例化客户端对象时通过设置options参数来定义键前缀:

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

I'm storing more than just sessions in one Redis instance. 我在一个Redis实例中存储的不仅仅是会话。 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. 我假设Predis正在跨客户端实例共享连接和选项。 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. 在Github上找到了一个相关的问题,作者的回答是不支持这个问题。

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. Predis\\Session\\SessionHandler只是为了注入而接受客户端实例,但你不应该真正重用该客户端用于其他任何事情......显然,对于非常特定的场景,没有什么能阻止你编写自己的会话处理程序。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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