Skip to content

Instantly share code, notes, and snippets.

@BetterProgramming
Created May 3, 2021 14:45
Show Gist options
  • Save BetterProgramming/67fe021b24fe500c7f1f940287ae6e05 to your computer and use it in GitHub Desktop.
Save BetterProgramming/67fe021b24fe500c7f1f940287ae6e05 to your computer and use it in GitHub Desktop.
"""
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