du5407 2018-08-11 01:46
浏览 173
已采纳

你如何在Symfony 4中使用RedisSessionHandler? 破碎的文档

The documentation is broken and leads to a 404 page. I'm not too good at reverse engineering classes like this, any tips on how to setup services.yml to use it?

Doc page https://symfony.com/doc/current/components/http_foundation/session_configuration.html

Session Handler 404 https://api.symfony.com/4.1/Symfony/Component/HttpFoundation/Session/Storage/Handler/RedisSessionHandler.html

Git Page for Session Handler https://github.com/symfony/symfony/blob/master/src/Symfony/Component/HttpFoundation/Session/Storage/Handler/RedisSessionHandler.php

  • 写回答

2条回答 默认 最新

  • douyan1972 2018-08-14 14:52
    关注

    You need to define 2 services:

    • One for the Redis connection.
    • One for RedisSessionHandler that will make use of that connection.

    Edit the services file:

    # config/services.yaml
    services:
        Redis:
            class: Redis
            calls:
                - method: connect
                  arguments:
                      - '%env(REDIS_HOST)%'
                      - '%env(int:REDIS_PORT)%'
                # If you need key prefix
                # - method: setOption
                #   arguments:
                #       - !php/const Redis::OPT_PREFIX
                #       - 'my_prefix'
    
        Symfony\Component\HttpFoundation\Session\Storage\Handler\RedisSessionHandler:
            arguments:
                - '@Redis'
    

    (note that I stored here the Redis host & port as environment variables, but you can define them elsewhere if needed).

    You can now make use of the service as your session handler:

    # config/packages/framework.yaml
    framework:  
        session:
            handler_id: Symfony\Component\HttpFoundation\Session\Storage\Handler\RedisSessionHandler
    

    I struggled a bit too, and wrote a more detailed articled: http://blog.michaelperrin.fr/2018/08/14/redis-session-handling-in-symfony/

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥30 这是哪个作者做的宝宝起名网站
  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!