Created
May 3, 2021 14:45
-
-
Save BetterProgramming/67fe021b24fe500c7f1f940287ae6e05 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
An oversimplified implementation of the Python interface for Redis | |
""" | |
class Redis: | |
def __init__(self, db=0): | |
self.db = db | |
self.data = {self.db: {}} | |
def get(self, key): | |
"""Gets the value associated with a key""" | |
return self.data.get(self.db, {}).get(key) | |
def set(self, key, value): | |
"""Sets a key-to-value association""" | |
self.data[self.db][key] = value | |
return True | |
def delete(self, key): | |
"""Deletes a key""" | |
del self.data[self.db][key] | |
return True |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment