Error in redis_cache.py after upgrading web2py to last stable version

61 views
Skip to first unread message

Lisandro

unread,
Sep 28, 2016, 10:24:10 AM9/28/16
to web2py-users
Hi there! 
Recently I've updated web2py to the last stable version 2.14.6-stable+timestamp.2016.05.10.00.21.47


ERROR:web2py:Traceback (most recent call last):
  File "/home/gonguinguen/medios/gluon/restricted.py", line 227, in restricted
    exec ccode in environment
  File "/home/gonguinguen/medios/applications/webmedios/models/0.py", line 19, in <module>
    cache.redis = RedisCache('localhost:6379', with_lock=True)
  File "/home/gonguinguen/medios/gluon/contrib/redis_cache.py", line 90, in RedisCache
    with_lock=with_lock, fail_gracefully=fail_gracefully))
  File "/home/gonguinguen/medios/gluon/contrib/redis_cache.py", line 126, in __init__
    self._release_script = register_release_lock(self.r_server)
  File "/home/gonguinguen/medios/gluon/contrib/redis_utils.py", line 69, in register_release_lock
    rtn = conn.register_script(_LUA_RELEASE_LOCK)
AttributeError: 'str' object has no attribute 'register_script'


Any ideas on how to solve it?
I'm a bit lost. I've tried instantiating RedisCache with_lock=False but the error is the same.

Thanks in advance!
Regards,
Lisandro.

Marlysson Silva

unread,
Sep 28, 2016, 10:52:22 AM9/28/16
to web2py-users
Try look whether a instance of Redis return a type of redis , it is like that redis connection are failing and returning a string intead redis object. I Think.

Lisandro

unread,
Sep 28, 2016, 11:54:13 AM9/28/16
to web...@googlegroups.com
I was using an old web2py version (2.10.3-stable+timestamp.2015.04.02.21.42.07), but today I've updated to the last stable (2.14.6-stable+timestamp.2016.05.10.00.21.47).

I've seen that in the new version of redis_cache the usage has changed. Before it was like this:

from gluon.contrib.redis_cache import RedisCache

cache
.redis = RedisCache('localhost:6379', with_lock=True)


But now, accordingly to the module documentation, it should be like this:

from gluon.contrib.redis_cache import RedisCache
from gluon.contrib.redis_utils import RConn
rconn
= RConn('localhost', 6379)
cache
.redis = RedisCache(redis_conn=rconn, with_lock=True)


I've made that changes, and it does work ok when I use web2py embedded webserver, but when I stop web2py's server and try to access the app (served through nginx), it can't connect to redis.
I'm lost there :/

Lisandro

unread,
Sep 28, 2016, 3:42:28 PM9/28/16
to web2py-users
I think I know what's going on.
I've found this post from Niphlod regarding new redis cache:

There he says: "...want to connect to redis through ssl (previously unavailable)? pass the relevant ssl, ssl_keyfile, etc etc etc to RConn"

My app is served with nginx through HTTPS, so I think I would have to pass those parameters to RConn.
Does anyone have a working example about that?

Niphlod

unread,
Sep 28, 2016, 5:39:25 PM9/28/16
to web2py-users
see the other thread. accessing redis through an ssl channel just encrypts the traffic from your frontend to the redis instance: it has nothing to do with how a user accesses your app (i.e. https or http). 

Lisandro

unread,
Sep 28, 2016, 5:53:09 PM9/28/16
to web2py-users
Thank you Niphlod, as always :)
I've seen your answer in the other post. Sorry for my lack of knowledge :P
Now I understand better.

I was dealing today with a strange error: the same code worked ok when I run the app with web2py's embedded server, but the app couldnt connect to redis when I used nginx (the logs showed that there was no redis instance available, same message every two seconds, until it gave up). But it was fixed after restarting the OS. Sorry, I've should tried that.

Anyway, this code is working ok:

from gluon.contrib.redis_cache import RedisCache
from gluon.contrib.redis_utils import RConn
rconn
= RConn('localhost', 6379)
cache
.redis = RedisCache(redis_conn=rconn, with_lock=True)



Thanks for your time, sorry for the bother!
Regards,
Lisandro.
Reply all
Reply to author
Forward
0 new messages