1

I can save a dict as a string in redis as follows:

>>> r.set( 
           'rt.http://rottentomatoes.com/m/771354525/', 
           {"Director": "blasco ricardo", "Platform": "RT"}
         )

How would I save the dict as a dict/hash directly so I wouldn't have to use json.loads to read it into a dict? Currently, if I do r.get() I get the dict as a string:

>>> r.get('rt.http://rottentomatoes.com/m/771354525/')
'{"Director": "blasco ricardo", "Platform": "RT"}'

1 Answer 1

4

Look into hmset

HMSET 'rt.http://rottentomatoes.com/m/771354525/' Director "blasco ricardo" Platform "RT"

Then you can retrieve it with

HGETALL rt.http://rottentomatoes.com/m/771354525/

Or a specific field with

HGET rt.http://rottentomatoes.com/m/771354525/ Director

In python it would be

r.hmset('rt.http://rottentomatoes.com/m/771354525/', {'Director': 'blasco ricardo', 'Platform': 'RT'})
r.hgetall('rt.http://rottentomatoes.com/m/771354525/')
r.hget('rt.http://rottentomatoes.com/m/771354525/', 'Director')
Sign up to request clarification or add additional context in comments.

Comments

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.