librelist archives

« back to archive

Too big data to store in session

Too big data to store in session

From:
Mic
Date:
2014-11-05 @ 04:03
Hi,
I was not able to store a list in session from the below module, because it
was too big.

*    from flask import Flask, session*

*    users = session.get('users',None)    if total_users is None:
g.cur.execute('select name from users order by name')
session['users'] = total_users = g.cur.fetchone()[0]*

I heard about *from flask.ext.cache import Cache* and also to store session
in:
* MongoDB: http://flask.pocoo.org/snippets/110/
* Redis: http://flask.pocoo.org/snippets/75/

However, I do not know how to covert the above session example to MongoDB
or Redis.

Thank you in advance.

Mic

Re: [flask] Too big data to store in session

From:
Jack Maney
Date:
2014-11-05 @ 04:44
Before you go about implementing a cache, do you really *need* to have a
list of every username on hand?

On Tue, Nov 4, 2014 at 10:03 PM, Mic <mictadlo@gmail.com> wrote:

> Hi,
> I was not able to store a list in session from the below module, because
> it was too big.
>
> *    from flask import Flask, session*
>
> *    users = session.get('users',None)    if total_users is None:
> g.cur.execute('select name from users order by name')
> session['users'] = total_users = g.cur.fetchone()[0]*
>
> I heard about *from flask.ext.cache import Cache* and also to store
> session in:
> * MongoDB: http://flask.pocoo.org/snippets/110/
> * Redis: http://flask.pocoo.org/snippets/75/
>
> However, I do not know how to covert the above session example to MongoDB
> or Redis.
>
> Thank you in advance.
>
> Mic
>
>


-- 
"Structures are the weapons of the mathematician."
--Bourbaki

Re: [flask] Too big data to store in session

From:
Daniel Neuhäuser
Date:
2014-11-05 @ 06:55
The redis snippet you linked to illustrates how it works rather well. 

You need to create a SessionInterface which you use to replace the default
one. The documentation explains the methods the SessionInterface must 
provide. 

Existing implementations like the default one or the redis based one you 
linked to are also a helpful reference.