<small id='Q9GS9'></small><noframes id='Q9GS9'>

  1. <tfoot id='Q9GS9'></tfoot>
    • <bdo id='Q9GS9'></bdo><ul id='Q9GS9'></ul>

    1. <legend id='Q9GS9'><style id='Q9GS9'><dir id='Q9GS9'><q id='Q9GS9'></q></dir></style></legend>
      <i id='Q9GS9'><tr id='Q9GS9'><dt id='Q9GS9'><q id='Q9GS9'><span id='Q9GS9'><b id='Q9GS9'><form id='Q9GS9'><ins id='Q9GS9'></ins><ul id='Q9GS9'></ul><sub id='Q9GS9'></sub></form><legend id='Q9GS9'></legend><bdo id='Q9GS9'><pre id='Q9GS9'><center id='Q9GS9'></center></pre></bdo></b><th id='Q9GS9'></th></span></q></dt></tr></i><div id='Q9GS9'><tfoot id='Q9GS9'></tfoot><dl id='Q9GS9'><fieldset id='Q9GS9'></fieldset></dl></div>

    2. Laravel 使用 Redis 驱动程序的所有会话 ID

      时间:2023-10-04
      <legend id='0Y12Z'><style id='0Y12Z'><dir id='0Y12Z'><q id='0Y12Z'></q></dir></style></legend>
          <tbody id='0Y12Z'></tbody>

          <tfoot id='0Y12Z'></tfoot>

          <small id='0Y12Z'></small><noframes id='0Y12Z'>

          • <bdo id='0Y12Z'></bdo><ul id='0Y12Z'></ul>
            • <i id='0Y12Z'><tr id='0Y12Z'><dt id='0Y12Z'><q id='0Y12Z'><span id='0Y12Z'><b id='0Y12Z'><form id='0Y12Z'><ins id='0Y12Z'></ins><ul id='0Y12Z'></ul><sub id='0Y12Z'></sub></form><legend id='0Y12Z'></legend><bdo id='0Y12Z'><pre id='0Y12Z'><center id='0Y12Z'></center></pre></bdo></b><th id='0Y12Z'></th></span></q></dt></tr></i><div id='0Y12Z'><tfoot id='0Y12Z'></tfoot><dl id='0Y12Z'><fieldset id='0Y12Z'></fieldset></dl></div>
                本文介绍了Laravel 使用 Redis 驱动程序的所有会话 ID的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                问题描述

                在我的应用程序中,我希望允许某些用户退出除他/她之外的所有其他用户.我已经完成了这个功能,当会话驱动程序设置为文件时,但现在我使用 redis 作为会话驱动程序,我无法找到任何方法来列出所有当前会话,就像我在文件时所做的那样司机.

                In my application I want to allow for some user, to be able to sign out all other users except him/her. I have done this functionality, well, when the Session driver was set to file, but now I'm using redis as session driver and I could not able to find any way to list up all current sessions like I have done when it was file driver.

                问题是:使用redis作为会话驱动时,如何列出所有会话ID?

                The question is: How to list up all sessions IDs when using redis as a session driver?

                以下是我在 session driver 为 file 时使用的代码:

                The following is the code that I have used when session driver was file:

                public function signoutAllUsers(Request $request,$sesId=null){
                        //dd(session());
                        if ($sesId == session()->getId()){
                            $dir = storage_path().'/framework/sessions';
                            $files = scandir($dir);
                            foreach ($files as $file){
                                if ($file == session()->getId() || strpos($file,'.') !== false){
                                    //echo "ggg";
                                    continue;
                                }
                                try{
                                    unlink($dir.'/'.$file);
                                }
                                catch(Exception $e){
                                    return $e;
                                }                
                
                            }
                            $request->session()->flash('status','success');
                            $request->session()->flash('msg',__('All users have been signed out successfully'));
                            return redirect('/method/create');
                
                        }
                        else{
                            return redirect('/method/create');
                        }
                
                    }
                

                更新

                我找到了一个有限的解决方案,它依赖于 Redis 门面方法 command:

                <代码>Redis::command('keys',['*'])但是,它返回的输出如下所示:

                Redis::command('keys',['*']) However, it returns output looks like:

                <代码>数组:4 [▼0 =>laravel:cav17Job1_7l46wAdE2--__"1 =>laravel:cav17Job1_7l46wAdE2--_"2 =>laravel:WwerTYmw2VNAfR5nKj3OOGBp2hKytSBK4MWMJ2P9"3 =>laravel:12tyuwzoFhXPM4f6w4yRPxrYywPon4W41neq6gu"]上面的输出包含会话 ID 和其他缓存条目,在我的应用程序中,我也使用 Redis 进行缓存.

                array:4 [▼ 0 => "laravel:cav17Job1_7l46wAdE2--__" 1 => "laravel:cav17Job1_7l46wAdE2--_" 2 => "laravel:WwerTYmw2VNAfR5nKj3OOGBp2hKytSBK4MWMJ2P9" 3 => "laravel:12tyuwzoFhXPM4f6w4yRPxrYywPon4W41neq6gu" ] The above output contains both sessions ids and other cache entries, in my application I am using Redis for cache too.

                问题变成了,我如何给存储在 redis 中的会话提供不同于作为缓存键的 laravel 的键?

                The question becomes, How could I give sessions stored in redis, different key other than laravel which is the cache key?

                推荐答案

                保持 session 和 cache 分开.

                在文件configdatabase.php

                您可以设置多个 redis 连接,默认情况下有一个"default" 但您可以添加更多连接

                You can set many redis connections, by default there is a "default" but you can add more to it

                假设你创建了 'session-connection' 和 'cache-connection'

                现在你需要利用它

                转到文件'configsession.php'

                go to file 'configsession.php'

                并将其设置为 'connection' =>'会话连接',

                然后转到文件 configcache.php

                并将其设置为

                    'redis' => [
                        'driver'     => 'redis',
                        'connection' => 'cache-connection',
                    ],
                

                现在你可以得到你的 redis 会话记录.

                and now you can get your redis session records.

                use IlluminateSupportFacadesRedis;
                Log::debug( Redis::connection('session-connection')->keys('*') );
                

                这篇关于Laravel 使用 Redis 驱动程序的所有会话 ID的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                上一篇:Laravel 6 config()->get('database.connections.mysql 下一篇:如何使用官方 PHP Docker 映像方法安装 php-redis 扩展

                相关文章

                最新文章

              1. <small id='t88AT'></small><noframes id='t88AT'>

              2. <tfoot id='t88AT'></tfoot>

                1. <i id='t88AT'><tr id='t88AT'><dt id='t88AT'><q id='t88AT'><span id='t88AT'><b id='t88AT'><form id='t88AT'><ins id='t88AT'></ins><ul id='t88AT'></ul><sub id='t88AT'></sub></form><legend id='t88AT'></legend><bdo id='t88AT'><pre id='t88AT'><center id='t88AT'></center></pre></bdo></b><th id='t88AT'></th></span></q></dt></tr></i><div id='t88AT'><tfoot id='t88AT'></tfoot><dl id='t88AT'><fieldset id='t88AT'></fieldset></dl></div>

                      <bdo id='t88AT'></bdo><ul id='t88AT'></ul>
                    <legend id='t88AT'><style id='t88AT'><dir id='t88AT'><q id='t88AT'></q></dir></style></legend>