Skip to content

Instantly share code, notes, and snippets.

@onelharrison
Forked from BetterProgramming/redisx.py
Created September 30, 2022 18:51
Show Gist options
  • Save onelharrison/a7f94cbbdb423a3a5cec0b3260466797 to your computer and use it in GitHub Desktop.
Save onelharrison/a7f94cbbdb423a3a5cec0b3260466797 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