Sunday, November 13, 2022

[FIXED] How do I check if a key exists in Memcache (AWS Elastic Cache instance) using python?

Issue

I'm trying to create a dynamic query which will be a part of memcache key. Is there any way to lookup keys in the memcache? I'm trying to acheive this because if there is any way, I would first lookup in that keymap and will create a new key only if it doesn't exist.

I'm using python + Pymemcache module.


Solution

Nevertheless, I found one simple way to check that. So, posting it as an answer.

if client.get(key) is None:
    //your_code


Answered By - Pavan
Answer Checked By - Timothy Miller (PHPFixing Admin)

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.