rc,redis缓存

rc的Python项目详细描述


rc: the redis cache

rc-redis缓存。

  • 易于使用
  • 可以构建缓存群集
  • 批量获取多个缓存结果(对群集并行执行)

有关完整文档,请参见rc.readthedocs.org

安装

$ pip install rc

快速启动

最小缓存示例如下:

fromrcimportCachecache=Cache()assertcache.set('key','value')assertcache.get('key')=='value'assertcache.get('foo')isNoneassertcache.set('list',[1])assertcache.get('list')==[1]

缓存群集使用redis群集作为后端:

fromrcimportCacheClustercache=CacheCluster({'cache01':{'host':'redis-host01'},'cache02':{'host':'redis-host02'},'cache03':{'host':'redis-host03'},'cache04':{'host':'redis-host04','db':1},})

缓存装饰器:

@cache.cache()defload(name,offset):returnload_from_database(name,offset)rv=load('name',offset=10)

批量获取多个缓存结果:

assertcache.get_many('key','foo')==['value',None]# for cache decorated function@cache.cache()defcached_func(param):returnparamresults=[]# with the context manager, the function# is executed and return a promisewithcache.batch_mode():foriinrange(10):results.append(cached_func(i))fori,rvinenumerate(results):assertrv.value==i

缓存失效:

cache.delete('key')# for decorated functioncache.invalidate(load,'name',offset=10)

更好

如果你觉得有什么不对劲,欢迎反馈或提出请求。

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
java接口中的每个方法都是抽象的,但在抽象类中,我们也只能使用抽象方法   初始化Java中声明的、未初始化的变量会发生什么情况?   java BouncyCastle openPGP将字节[]数组加密为csv文件   在Java中将类A(和所有子类)映射到类B的实例的字典   RSA公钥编码,在Java和Android中,代码相同,结果不同   java在安卓中实现数字检测语音识别   java取消选择复选框   java如何在其他配置中重用Maven配置XML片段   java有没有一种有效的方法来检查HashMap是否包含映射到相同值的键?   spring处理程序调度失败;嵌套的例外是java。lang.NoClassDefFoundError:org/apache/http/client/HttpClient   带有ehcache的java多层缓存   java如何访问chromium(或任何其他浏览器)cookie   java通过将两个集合与spring data mongodb data中的条件合并来获取计数   安卓中R.java的语法错误