django-redis-counter
Django application that keeps content visit count in redis first, then dump to database via extra job.
Install
pip install django-redis-counter
Dependencies
django
redis
Usage
Add drc in INSTALLED_APPS in django settings.py. drc is short for django-redis-counter.
INSTALLED_APPS = [
...
'drc',
...
]
Define counter models in app’s models.py.
from drc.models import Counter
class Page(models.Model):
title = models.CharField(max_length=32)
...
class PageCounter(Counter):
pass
Call incr in views.
def display_page(request, page_id):
page = Page.objects.get(pk=page_id)
page_visit_number = PageCounter.incr(page)
return render(request, "page.html", {
"page": page,
"page_visit_number": page_visit_number,
})
Create a script to dump cached data to database. Name the script to page_counter_dump.sh or what ever you like.
#!/bin/bash cd /your/project/path python manage.py drc-dump
Add dump task as schedule job, e.g. crontab job.
* * * * * page_counter_dump.sh # dump the cached data every minutes 1 * * * * page_counter_dump.sh # dump the cached data every hour.
Metadata
Release files for django-redis-counter 0.1.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| django-redis-counter-0.1.1.tar.gz | 4.0 kB | Without provenance | Details for django-redis-counter-0.1.1.tar.gz |
Release files / django-redis-counter-0.1.1.tar.gz
| Download URL | django-redis-counter-0.1.1.tar.gz |
|---|---|
| Size | 4.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
af64625dd1f09a1f986e052d4982f6156687d53010c2983a26e28660bd72ef33
|
|
BLAKE2b-256 checksum How to use checksums |
98df7ededad31f1f34e3a7dff62ef47e3d742cda4ef820e3b1ac6fb054c133b5
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
Security for django-redis-counter 0.1.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.