PythonAnywhere Forums

Redis

PythonAnywhere has built-in support for MySQL and it looks like Postgres is coming. Are there any plans or is there interest in adding support for Redis? I'm currently exploring using Redis Labs, but a local PythonAnywhere Redis instance would be even better. Thanks!

Redis is on our todo list. I've upvoted it for you.

Great! Thanks Glenn.

+1

+1 from me too!

noted and upvoted, thanks.

+1

How is your progress? Can you say when can we expect it?

What about redis ? Any progress ? I realy need it in my app

No progress I'm afraid. We'd be interested to hear what it is you want to use Redis for?

If you want a hacky workaround: I found out about a thing called redislite at Pycon, which is pretty cool. It gives you little throwaway instances of redis that you can spin up inside any python process, and I've tried installing it on PythonAnywhere, and it works.

but: it will spin up a separate redis instance for each of your web server worker processes, which is probably not what you want. You could try specifying the rdb file in the init, which might make it share one redis instance per server, which would be better, but even then you wouldn't get redis shared on different servers, and I don't know what would happen when worker processes die, whether you'd get nice tidy-up.... Worth experimenting with, maybe?

I didn't realize that this wasn't being actively worked on. Here is my use case:

I need to use server-side sessions in my Flask app. I'm using Flask-KVSession for this purpose. Redis or memcache would be the best choices for this, but I'm forced to use a mysql backend. This has inherent challenges, especially when a single client makes many concurrent requests--a SQL database isn't designed for this (see https://github.com/mbr/flask-kvsession/issues/25 for some details on one of the issues I encounter in production on PythonAnywhere).

Hope that helps.

Ah. I wonder how django solve this problem? We've been using mysql sessions in django for years without any problem...

I want to provide a web based json output of various data elements related to a satellite (computed once - stored in memory). Rather than every single web session calculating everything from scratch at each page refresh. Doing this via MySQL is really just overkill - as it's really not the type of data that needs to be handled via a relational database.

Sounds fair enough, sorry we can't be more helpful. Redis is on the horizon, but I'd say medium-term rather than short-term. In the meantime, MySQL is probably a better option than recomputing every time. redislite may also work for your needs, @issabobe, but probably not for storing sessions @jons. Postgres might also be a good solution if you're storing json data...

What about storing complex custom objects? One of the API's I'm working with requires me to make a custom object available across different views in Flask. I can't store the object in session (since it won't jsonify) and this SO article recommends using Redis, what would be the best alternative on PythonAnywhere? The object is a "connect" object from when the user authenticates and I need to allow the user to access that connect object across multiple views as they make new requests to the API.

I feel like, surely, anything you can put in redis must be jsonify-able? But anyways, my first step would be to store it in the database and see how that performs.

I am hoping to use http://swampdragon.net, which involves Redis and Websockets - both problematic for PA, it seems!

FYI, I don't mind paying a modest amount for a good hosting service but services like OpenShift and AWS look too complex for me, plus the latter and Google's offerings cost too much. Plus PA is UK-based I think, which makes a nice change.

So if you guys can keep it simple (i.e. a console with 'su' rights) and provide support for all the 'fancy' stuff then I will pay!

Cheers,

Richard

Cool! We are indeed UK-based (though we actually host everything on AWS in the US). "su" doesn't work with our virutalisation system, but hopefully everything you need is either pre-installed, or can be installed using pip install --user XXXX.

We'd love to hear how things work out with SwampDragon BTW. They look really interesting!

Hello Giles

Connected question then:

Is there any way to get PA in the EU region?

If the answer is no, should I move my Mongolabs mongodb instance to a US AWS? Thanks

We don't have any machines in the EU region at the moment. Moving your mongodb instance to us-east will improve the speed of accessing your mongodb instance from PythonAnywhere.

Is support for redis any closer than it was a year ago?

It is not. With that said, you might be able to get Redis working in some shape or form by using redislite -- you can set it to use a path on disk as its socket, which should ensure that multiple web workers on the same server would all be talking to the same instance...

Let us know how you get on if you do decide to experiment with it!

Thanks for the suggestion - that does indeed look promising. All I'm really trying to do is to have access to a simple shared data structure (just three variables) for use within a flask application and I am probably overthinking the issue. It might just be easier to work with MySQL even though it's really not a database type need.

So I accomplished my needs by using a pure file based system (ConfigParser) and a file based lock using zc.lockfile.

My requirement is so minimal - that's working perfectly for me.

Any one help me to run redis on pythonanywhere

The best option is to use one from a third-party provider. If you start one with, say, RedisLabs, in the us-east-1 availability zone, then access to it from PythonAnywhere should be pretty fast.

Hi Dim,

Redis is indeed a TCP protocol. If pythonanywhere supports only HTTP and HTTPS, we don't see a way to communicate with them.

Best Regards, The Redis Labs Team

Hi there,

To be clear -- we absolute do support TCP protocols, just not for free users. If you upgrade to a paying account, you'll be able to access redislabs (like many of our other users do already).

Why not just try it out? We offer a full 30-day money-back guarantee, so if there are any problems and you can't get it working within a month, we'll happily refund you...

I was looking at this here to use Redis for sessions. Where do we need to specify it to connect to external Redis ?

http://flask.pocoo.org/snippets/75/

Look at the __init__ function of the RedisSessionInterface in the snippet that you link to.

You should either create the redis connection yourself and pass it in, or give the default Redis() call the relevant parameters (eg: host, port etc)

How to use RedisLabs with web2py? (assume you are speaking to a novice)

Hmm, there's no real PythonAnywhere-specific stuff in using it from a paid account; you just connect as if you were connecting from a web2py instance running on (say) your own machine.

Now, as to how you'd use it with web2py in general -- that would depend very much on what you wanted to use it for. I think the web2py users Google group will probably be able to give better advice on that than we can.

the purpose for running with web2py is to keep all sessions on redis. Anything specific tips?

Nothing PythonAnywhere-specific I can think of. As far as I can tell, it's built in to web2py, so you should be good to go if you follow the instructions in the web2py docs.

Oh, hang on -- one PythonAnywhere-specific thing just came to mind -- if you're starting a RedisLabs instance to use with PythonAnywhere, you should put it in the AWS/us-east-1 region -- that will be closest to our servers, so the performance will be best that way.