[Tutor] get key value from Redis instance

Danny Yoo dyoo at hashcollision.org
Sun May 27 18:11:53 EDT 2018


On Sun, May 27, 2018 at 3:02 PM Silviu Chiric <silviuchiric at gmail.com>
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

What is the error you see?  Please also include the error message, verbatim.

Computer systems are complex.  You've made an assumption that something in
your program is causing the error that you're seeing.  But there might be
some other cause.  In order to help the volunteers here to accurately
diagnose problems, you should try to also include error message output in
your report.

Also, it is normally a bad idea to include password information in a
program's source code.  I would *strongly* suggest you change your password
to your Redis database if it's a real password, as you've just
inadvertently shared it with the rest of the open Internet.

 From a first glance: it looks like one of your print statements is not
vertically aligned with the rest of your print statements, so I would
expect Python to be reporting a SyntaxError because of this misalignment.

I would also recommend not to combine mutation statements with print
statements.  That is, rather than:

##############
print 'Set Record:', conn.set("best_car_ever", "Tesla Model S")
##############

do this instead:

##############
set_result = conn.set("best_car_ever", "Tesla Model S")
print 'Set Record:', set_result
##############


Likewise, I'd recommend separating out:

##############
print 'Delete Record:', conn.delete("best_car_ever")
##############

into:

##############
delete_result = conn.delete("best_car_ever")
print 'Delete Record', delete_result
##############

These changes are intended to help with the readability of the program,
because the important statements that modify the database will stand out.
Compare with the previous, where because those modification statements are
nested within the 'print' statement, they are easier to overlook.


Hope that makes sense.  Good luck to you!


More information about the Tutor mailing list