[Tutor] get key value from Redis instance

Alan Gauld alan.gauld at yahoo.co.uk
Sun May 27 18:16:00 EDT 2018


On 27/05/18 19:31, Silviu Chiric wrote:
> Dear all
> 
> I need to get the value of given key from Redis, or both key and value, the
> below code snippet fails always, even the connection is okay

Please post the output. You print the error trace but we cant see it.

Or if that is the the whole output please remove the try/except clause
since it may be hiding valuable error information.

> import redis
> 
> try:
>     conn = redis.StrictRedis( host='
> redis-15838.c44.us-east-1-2.ec2.cloud.redislabs.com', port=15838,
> password='DavidLavinia2')
>     print (conn)
>     conn.ping()
>     print ('Connected!')
> print 'Set Record:', conn.set("best_car_ever", "Tesla Model S")

This appears to break indentation, but I'd expect an error
so I assume its an email issue.

If not, fix this first!


>     print 'Get Record:', conn.get("best_car_ever")
>     print 'Delete Record:', conn.delete("best_car_ever")
>     print 'Get Deleted Record:', conn.get("best_car_ever")
> except Exception as ex:
>         print ('Error:', ex)
>         exit('Failed to connect, terminating.')


-- 
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.amazon.com/author/alan_gauld
Follow my photo-blog on Flickr at:
http://www.flickr.com/photos/alangauldphotos




More information about the Tutor mailing list