Skip to main content

Python implementation of go-redis/cache

Project description

vcache

阅读 go-redis/cache 的代码后,为了理解原代码,遂用Python 实现了一个版本。

(py3.7 编写,其他版本未经测试)

Feature

  • 支持缓存 Python的所有内置对象以及自定义类实例
  • 支持自定义 local_cache

Install

pip install vcache

Usage

without redis

>>> from vcache import Cache, Item
>>> value = "Hello, World, Hello 中国"
>>> key = "key"
>>> item = Item(key, value)
>>> cache = Cache()
>>> cache.set(item)
True
>>> cache.get(key)
'Hello, World, Hello 中国'
>>>

use redis

>>> from redis import Redis
>>> from vcache import Cache, Item, Option
>>> r = Redis(host='localhost', port=6379, db=0)
>>> opt = Option(redis=r, stats_enabled=True)
>>> cache = Cache(opt=opt)
>>> value = "Hello, World, Hello 中国"
>>> key = "key"
>>> item = Item(key, value)
>>> cache.set(item)
True
>>> cache.get(key)
'Hello, World, Hello 中国'
>>> cache.get(key, skip_local_cache=True)
'Hello, World, Hello 中国'

Test

pip install -r req-test.txt
python -m pytest test_vcache.py -v

Link

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

vcache-0.0.7.tar.gz (5.9 kB view hashes)

Uploaded Source

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page