Reputation: 91
Trying to read a hash key and field from redis Database using python. In the DB i have many numeric keys(0,1,2,etc), and each has a TIMESTAMP field with the time value (2021-08-07 11:28:07.330731)
I can read the hash key and also read the desired field, individually.
How do I get it to read\list and print out to either screen or a variable the hash key associated with the desired field value.
r = myRedis database
field = r.hget('0','TIMESTAMP') # this gives me the field "TIMESTAMP" value, from Hash with key '0' and intkeylist = r.keys() # gives me the key list
just not sure how to tie these two together, so I get all my keys associated with the fields "TIMESTAMP"(value) listed together
Desired OUTPUT: Key Field value
etc...
Upvotes: 0
Views: 664
Reputation: 490
timestamps_log = ""
for x in intkeylist:
timestamps_log += str(x + r.hget(x,'TIMESTAMP'))
print(timestamps_log)
Upvotes: 1