Hi,
Im creating a Redis database with Jupyter notebook. I have created some users and values but, when I try to use them in fuctions, it seems that they dont exist.
If I print the keys:
keys = r.keys('*')
for key in keys:
print(key.decode())
I obtain something like that:
user:name:animalhealtheu
following:b'1'
post:9
followers:b'1'
followers:b'3'
user:name:seers_helen
If I use
user_id = r.get('user:name:seers_helen')
print(user_id)
the output is the key b’8’
Therefore those users and keys are created, but now if I try to use this function:
def obtener_followings(usuario):
# User ID
user_id = r.get(f'user:id:{usuario}')
if user_id is None:
print(f'user {usuario} does not exist')
return
followings = r.zrange(f'following:{user_id}', 0, -1, withscores=True)
for following_id, timestamp in followings:
following_name = r.get(f'user:name:{following_id}').decode('utf-8')
timestamp_str = datetime.fromtimestamp(timestamp).strftime('%Y-%m-%d %H:%M:%S')
print(f'{following_name} - {timestamp_str}')
I obtain the output that the user does not exist, like if it returned a none value, but the user exists and has keys.
What could be happening?
thanks in advance