简体   繁体   English

在symfony4中为redis设置无键前缀

[英]Setting no key prefix in symfony4 for redis

I have a problem with proper configuration for redis in Symfony 4. I want to have no prefix before my cache item keys, but it is constantly showing. 我在Symfony 4中正确配置redis时遇到问题。我希望在缓存项目键之前没有前缀,但它会不断显示。 Here is my config/packages/framework.yaml (part related to cache): 这是我的config/packages/framework.yaml (与缓存相关的部分):

cache:
    prefix_seed: ztw/ztw
    app: cache.adapter.redis
    default_redis_provider: '%env(resolve:REDIS_URL)%'

I tried to remove prefix_seed key and setting its value to ~ . 我试图删除prefix_seed键并将其值设置为~ Nothing worked. 没有任何效果。 However, documentation states that its default value is null . 但是,文档说明其默认值为null

I want to achieve this because when I launch my website through the website, it sets some key and sticks to it. 我想实现这一点,因为当我通过网站启动我的网站时,它设置了一些关键并坚持下去。 But when I run my behat tests (intentionally - to populate cache) - keys are different, no matter what. 但是当我运行我的behat测试(故意 - 填充缓存)时 - 密钥是不同的,无论如何。 Both use APP_ENV=dev environment variable value (checked twice). 两者都使用APP_ENV=dev环境变量值(检查两次)。

Here is what's going on on the redis side: 以下是redis方面的情况:

127.0.0.1:6379> keys *
 1) "xw+Y6oICD-:4dfbddf6bbb8ea2e25e843d936739dd9"
 2) "xw+Y6oICD-:4f1cbb7ece6f8db3b69ae11418bbf022"
 3) "xw+Y6oICD-:26c65dcee950a5020596989ad1a8ff66"
 4) "gUbUjDoAuQ:b712bf9832f566bd5bd30a07e7bd146b"
 5) "gUbUjDoAuQ:1d0f56bf67bd482674b62067336bd633"
 6) "xw+Y6oICD-:d948f5e23f94e681620436786f0daf98"
 7) "xw+Y6oICD-:ef88ab906981c6e04ef639cd4a8ae803"
 8) "xw+Y6oICD-:748d18ce6ba0929d2540e9b4529e56cc"
 9) "xw+Y6oICD-:ef30ff7e239b92cec1f5e58c201296f5"
10) "xw+Y6oICD-:1d0f56bf67bd482674b62067336bd633"
11) "xw+Y6oICD-:b712bf9832f566bd5bd30a07e7bd146b"
12) "xw+Y6oICD-:4da534491b5732336b3bb3e7302bc79b"

For example 4th and 11th item have the same key (and value) but different prefix, unfortunately. 例如,第4和第11项具有相同的键(和值)但不幸的是前缀不同。

I know that cache key prefix is considered a good practice, but for some reason while running through behat keys are different. 我知道缓存键前缀被认为是一种很好的做法,但由于某种原因,在运行时,behat键是不同的。

Any help appreciated. 任何帮助赞赏。

The prefix_seed mentioned above is the prefix for the symfony cache files (unrelated redis). prefix_seed提到的prefix_seed是symfony缓存文件的前缀(不相关的redis)。

The default value for the redis prefix is PHPREDIS_SESSION: which explains the keys you mentioned above, I've not tried this but I think you will need to add and set the prefix option to an empty string in session.save_path . redis前缀的默认值是PHPREDIS_SESSION:它解释了上面提到的键,我没试过,但我认为你需要在session.save_path添加和设置prefix选项为空字符串。

Check the predis read me file: https://github.com/phpredis/phpredis 检查predis read me文件: https//github.com/phpredis/phpredis

Edit: according to the docs it looks like it's only possible to set extra settings via predis. 编辑:根据文档看起来它只能通过predis设置额外的设置。

When using the Predis library some additional Predis-specific options are available. 使用Predis库时,可以使用一些其他Predis特定选项。 Reference the Predis Connection Parameters documentation for more information. 有关更多信息,请参阅Predis连接参数文档。

Source: https://symfony.com/doc/current/components/cache/adapters/redis_adapter.html 资料来源: https//symfony.com/doc/current/components/cache/adapters/redis_adapter.html

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

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