在django应用程序中,在哪里存储键/值数据

时间:2021-05-29 23:06:31

I need to store dynamic (will change every day/hour) value in django app. Value will be generated every day, and I will need access to this key:value from all views in the application. I don't want to store it in some model object instance, it should work like settings.py but I need to store it in database instead. Any ideas?

我需要在django app中存储动态(每天每小时都会改变)值,每天都会生成值,我需要访问这个键:从应用程序的所有视图中获取值。我不想把它存储在某个模型对象实例中,它应该像设置一样工作。但是我需要把它存储在数据库中。什么好主意吗?

2 个解决方案

#1


1  

what about leveldb? https://code.google.com/p/leveldb/

leveldb呢?https://code.google.com/p/leveldb/

LevelDB is a fast key-value storage library written at Google that provides an ordered mapping from string keys to string values.

LevelDB是一个在谷歌上编写的快速键值存储库,它提供了从字符串键到字符串值的有序映射。

there is also python wrap https://code.google.com/p/py-leveldb/

还有python wrap https://code.google.com/p/py-leveldb/

or if you need distributed access checkout http://memcached.org/

或者如果需要分布式访问校验http://memcachedorg/

#2


0  

Why not use a key-value datastore like Redis? You can use it as a cache backend or as a normal store, it's fast and will persist your data. https://django-redis.readthedocs.org/en/latest/ https://pypi.python.org/pypi/redis/2.10.1

为什么不使用像Redis这样的键值数据存储呢?您可以将它用作缓存后端或普通存储,它速度很快,并且可以保存数据。https://django-redis.readthedocs.org/en/latest/ https://pypi.python.org/pypi/redis/2.10.1

#1


1  

what about leveldb? https://code.google.com/p/leveldb/

leveldb呢?https://code.google.com/p/leveldb/

LevelDB is a fast key-value storage library written at Google that provides an ordered mapping from string keys to string values.

LevelDB是一个在谷歌上编写的快速键值存储库,它提供了从字符串键到字符串值的有序映射。

there is also python wrap https://code.google.com/p/py-leveldb/

还有python wrap https://code.google.com/p/py-leveldb/

or if you need distributed access checkout http://memcached.org/

或者如果需要分布式访问校验http://memcachedorg/

#2


0  

Why not use a key-value datastore like Redis? You can use it as a cache backend or as a normal store, it's fast and will persist your data. https://django-redis.readthedocs.org/en/latest/ https://pypi.python.org/pypi/redis/2.10.1

为什么不使用像Redis这样的键值数据存储呢?您可以将它用作缓存后端或普通存储,它速度很快,并且可以保存数据。https://django-redis.readthedocs.org/en/latest/ https://pypi.python.org/pypi/redis/2.10.1