Saturday, February 4, 2012

Using redis in django views

Hello,

I'm trying to use redis (with redis-py) directly on some of my
critical views to lock them.
A simple version of the code could look like that :

def test_view(request):
--connec = redis.Redis(unix_socket_path='/tmp/vgbet_redis.sock')
--if connec.exists('test'):
----print 'Already locked'
--else:
----connec.set('test', '')
----for i in range(20):
------print '%i locked' % i
------time.sleep(1)
----connec.delete('test')
--return render_to_response("test.html", {},
context_instance=RequestContext(request))

The result of this code is very strange for me.
If I open two tabs of that view, the first view counts until 20 before
its template is displayed, then the second view starts counting. I was
expecting the second view to print just 'Already locked'.

I don't understand what I'm doing wrongly. Any help would be great.

Regards,

--
Ashe

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to django-users+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home


Real Estate