Skip to content

Instantly share code, notes, and snippets.

@djfroofy
Created May 24, 2010 20:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save djfroofy/412356 to your computer and use it in GitHub Desktop.
Save djfroofy/412356 to your computer and use it in GitHub Desktop.
from djredis.models import DredisMixin
import djredis.fields
class Blog(models.Model, DredisMixin): # inherit from the mixin class
author = models.ForeignKey('Author')
title = models.CharField(max_length=200)
viewcount = djredis.fields.Counter()
# optionally add a unique keyspace for the instance - default is shown below
def redis_key(self):
return '%s:%s:%s' % (self._meta.app_label, self._meta.module_name, self.pk)
blog = Blog.objects.get(pk=1)
blog.viewcount.incr()
# or equivalently:
blog.viewcount += 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment