3

I am using SQLAlchemy+SQLSoup to query a table, now I need to store the query result as a List in Redis. Any help on how-to would be great.

Thanks.

1 Answer 1

2

First, install redis-py then do:

>>> import redis
>>> r = redis.StrictRedis(host='localhost', port=6379, db=0)
>>> for e in yourlist:
...     r.rpush('yourlist', e)

If you have a complex structure (like an object or a tuple/list) I think your best bet is to serialize the data into some format you prefer (like json or, in case of python, pickle) and simply store it as a string:

>>> r.set('key', val)

Note that in Redis you can't query data by value, only by key. Details depend on your data, so if you need more precise answer please ask more precise question. :) A sample code would really be best.

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks @Michal, I understand the question was too vague, anyways let me be more clear, I need to store the query fieldname and its associated column values as a grouped list which is ordered. I will be frank, when working with Redis, I am novice. And to add up part of the query has a field which contains BLOB for file objects. Can you let me know if this can be implemented with Redis ? Thanks.
Thanks @Michal ,it does solve my problem. Yes we would be serializing the data and save them in Redis. Thanks again.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.