0

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

enter image description here

etc...

1
  • Fix your formatting first Commented Aug 7, 2021 at 18:15

1 Answer 1

1
timestamps_log = ""    
for x in intkeylist:
       timestamps_log += str(x + r.hget(x,'TIMESTAMP'))
print(timestamps_log)
Sign up to request clarification or add additional context in comments.

4 Comments

Ty, this works. Thought there would be a redis command for this.
@dancer Right, fixed.
and to dump to variable i would put? for x in intkeylist: keylist_timestamp = (x,r.get(x,'TIMESTAMP'))
@dancer like that

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.