未提供项目说明
cache-guiosoft的Python项目详细描述
缓存GUIOSOFT
使用文件、Redis或本地SQLite缓存数据
[]
用于缓存的本地文件
fromcache_gsimportCacheGS# Storage on local directoryfile_cache=CacheGS('path://directory_for_cache_storage')# Storage on local SQLite databaseslite_cache=CacheGS('sqlite://directory_or_file_for_storage')# Storage on Redisredis_cache=CacheGS('redis://host:6379')[Moreoptionsforredis](#Redis options and example)
使用
与INI文件一样,数据按节/键名称分组。在
安装
^{pr2}$写入值
cache.set_value(section,key,value,ttl:int=0)# ttl is the life time of value in seconds from the time is created
读数
value=cache.get_value(section,key,default=None)
删除值
cache.delete_value(section,key)
清除过期数据
- 在Redis缓存中,这由服务器自动处理。在
- 在SQLite缓存上,每次实例化都会执行清除。在
- 在Local File缓存中,清除每天自动执行一次,每次实例化时都要检查。在
强制清除过期数据
cache.purge_expired()
Redis选项和示例
Redis连接使用Andy McCurdy的redis-py component。 您可以使用与Redis类相同的连接字符串:
- 在
redis://[[用户名]:[密码]]@本地主机:6379/0在
在 - 在
redis://[[用户名]:[密码]]@本地主机:6379/0在
在 - 在
unix://[[用户名]:[密码]@/path/to/插座,袜子?分贝=0
在Three URL schemes are supported: - ```redis://`` <http://www.iana.org/assignments/uri-schemes/prov/redis>`_ creates a normal TCP socket connection - ```rediss://`` <http://www.iana.org/assignments/uri-schemes/prov/rediss>`_ creates a SSL wrapped TCP socket connection - ``unix://`` creates a Unix Domain Socket connection There are several ways to specify a database number. The parse function will return the first specified option: 1. A ``db`` querystring option, e.g. redis://localhost?db=0 2. If using the redis:// scheme, the path argument of the url, e.g. redis://localhost/0 3. The ``db`` argument to this function. If none of these options are specified, db=0 is used.
docker上的Redis
码头工人-合成.yaml在
redis:container_name:'redis'image:'redis:4-alpine'command:redis-server --requirepass 1234ports:-'6379:6379'
要进行测试,只需运行:
docker-compose up
- 项目
标签: