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条)

报告相同问题?

悬赏问题

  • ¥20 docker里部署springboot项目,访问不到扬声器
  • ¥15 netty整合springboot之后自动重连失效
  • ¥15 悬赏!微信开发者工具报错,求帮改
  • ¥20 wireshark抓不到vlan
  • ¥20 关于#stm32#的问题:需要指导自动酸碱滴定仪的原理图程序代码及仿真
  • ¥20 设计一款异域新娘的视频相亲软件需要哪些技术支持
  • ¥15 stata安慰剂检验作图但是真实值不出现在图上
  • ¥15 c程序不知道为什么得不到结果
  • ¥15 键盘指令混乱情况下的启动盘系统重装
  • ¥40 复杂的限制性的商函数处理