Skip to content

Instantly share code, notes, and snippets.

@skyl
Forked from djfroofy/djredis_iface.py
Created May 25, 2010 04:09

Revisions

  1. skyl revised this gist May 26, 2010. 1 changed file with 3 additions and 3 deletions.
    6 changes: 3 additions & 3 deletions djredis_iface.py
    Original file line number Diff line number Diff line change
    @@ -16,9 +16,9 @@ class Blog(models.Model, DredisMixin): # inherit from the mixin class
    1
    >>> blog.viewcount.incr(5)
    6
    >>> c.myzset
    >>> blog.myzset
    <SortedSet: []>
    >>> c.myzset.add('foo', 10)
    >>> blog.myzset.add('foo', 10)
    True
    >>> c.myzset
    >>> blog.myzset
    <SortedSet: ['foo']>
  2. skyl revised this gist May 26, 2010. 1 changed file with 12 additions and 2 deletions.
    14 changes: 12 additions & 2 deletions djredis_iface.py
    Original file line number Diff line number Diff line change
    @@ -1,14 +1,24 @@
    from djredis.models import DredisMixin
    import djredis.fields
    import djredis.models


    class Blog(models.Model, DredisMixin): # inherit from the mixin class
    author = models.ForeignKey('Author')
    title = models.CharField(max_length=200)
    viewcount = djredis.fields.Counter()

    # declaratively add your redis fields
    viewcount = djredis.models.Counter()
    myzset = djredis.models.Zset()


    >>> blog = Blog.objects.get(pk=1)
    >>> blog.viewcount.incr()
    1
    >>> blog.viewcount.incr(5)
    6
    >>> c.myzset
    <SortedSet: []>
    >>> c.myzset.add('foo', 10)
    True
    >>> c.myzset
    <SortedSet: ['foo']>
  3. skyl revised this gist May 26, 2010. 1 changed file with 5 additions and 7 deletions.
    12 changes: 5 additions & 7 deletions djredis_iface.py
    Original file line number Diff line number Diff line change
    @@ -6,11 +6,9 @@ class Blog(models.Model, DredisMixin): # inherit from the mixin class
    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
    >>> blog = Blog.objects.get(pk=1)
    >>> blog.viewcount.incr()
    1
    >>> blog.viewcount.incr(5)
    6
  4. @invalid-email-address Anonymous renamed this gist May 24, 2010. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion djredis_iface → djredis_iface.py
    Original file line number Diff line number Diff line change
    @@ -4,7 +4,7 @@
    class Blog(models.Model, DredisMixin): # inherit from the mixin class
    author = models.ForeignKey('Author')
    title = models.CharField(max_length=200)
    viewcount = djredis.fields.IntegerField()
    viewcount = djredis.fields.Counter()

    # optionally add a unique keyspace for the instance - default is shown below
    def redis_key(self):
  5. @invalid-email-address Anonymous created this gist May 24, 2010.
    16 changes: 16 additions & 0 deletions djredis_iface
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,16 @@
    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.IntegerField()

    # 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