python 在 Django 中,如何清除所有的 memcached 键和值?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1620072/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-11-03 22:43:21  来源:igfitidea点击:

In Django, how to clear all the memcached keys and values?

pythondjangocachingmemcached

提问by TIMEX

I don't want to restart the memcached server!

我不想重启memcached服务器!

回答by shanyu

from django.core.cache import cache
cache._cache.flush_all()

Also see this ticket, it has a patch (that I haven't tested) to flush any type of cache backend: http://code.djangoproject.com/ticket/11503

另请参阅这张票,它有一个补丁(我没有测试过)来刷新任何类型的缓存后端:http: //code.djangoproject.com/ticket/11503

回答by Wtower

And an one-liner from console:

来自控制台的单行:

echo "from django.core.cache import cache; cache._cache.flush_all()" | ./manage.py shell [--settings=myapp.settings_live]

回答by huseyin39

An easiest and fastest way:

最简单快捷的方法:

echo flush_all > /dev/tcp/localhost/11211