On Wed, Aug 17, 2011 at 11:54 AM, Marin Pranjić <marin.pran...@gmail.com>wrote:
> I tried to create an issue on code.google.com/p/web2py but it crashed > and are currently not working. I'm not sure if issue is created or > not. > > Here is c/p: > > > What steps will reproduce the problem? > 1. import memcache client: > > from gluon.contrib.memcache import MemcacheClient > memcache_servers = ['127.0.0.1:11211'] > cache.memcache = MemcacheClient(request, memcache_servers) > > 2. define test function > > def test(): > mem = cache.memcache('global_counter', lambda: 0, time_expire = > 100000) > mem = cache.memcache.increment('global_counter', 1) > > ram = cache.ram('global_counter', lambda: 0, time_expire = 100000) > ram = cache.ram.increment('global_counter', 1) > > return '%(mem)s : %(ram)s' % dict(mem = mem, ram = ram) > > 3. run in browser multiple times > > What is the expected output? What do you see instead? > > Expected: > 1 : 1 > 2 : 2 > 3 : 3 > 4 : 4 > ... > > Shown: > 1 : 1 > 1 : 2 > 2 : 3 > 3 : 4 > ... > > > What version of the product are you using? On what operating system? > > Trunk. > > Please provide any additional information below. > > Bug is in gluon/contrib/memcache/__init__.py in increment method of > class _MemcacheClient. > Line 66 creates a newKey by adding a prefix (app name). > Line 67 calls self.get(...) which adds another prefix, so the key is > prefixed twice. > Line 71 calls self.set(...) which also adds second prefix. > > Bugfix is either to call self.get and self.set with key instead of > newKey, or to call Client.set and Client.get instead. > > I attached a diff file which fixes the bug. > > Attached: > > diff -r 303827f25e8d gluon/contrib/memcache/__init__.py > --- a/gluon/contrib/memcache/__init__.py Tue Aug 16 12:35:25 2011 > -0500 > +++ b/gluon/contrib/memcache/__init__.py Wed Aug 17 11:25:10 2011 > +0200 > @@ -64,11 +64,11 @@ class _MemcacheClient(Client): > > def increment(self, key, value=1, time_expire=300): > newKey = self.__keyFormat__(key) > - obj = self.get(newKey) > + obj = Client.get(self, newKey) > if obj: > return Client.incr(self, newKey, value) > else: > - self.set(newKey, value, time_expire) > + Client.set(self, newKey, value, time_expire) > return value > > def set(self, key, value, time_expire=300): > > > > Marin
memcache_increment_bugfix
Description: Binary data