Skip to content

Instantly share code, notes, and snippets.

View onelharrison's full-sized avatar

Onel Harrison onelharrison

View GitHub Profile
"""
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)
import redisx
r = redisx.Redis(db=1)
r.set('hello', 'world') # True
value = r.get('hello')
print(value) # 'world'
r.delete('hello') # True
print(r.get('hello')) # None
import redis
import time
# Establish a connection to the Redis database 1 at
# redis://localhost:6379
r = redis.Redis(host='localhost', port=6379, db=1)
# SET hello world
r.set('hello', 'world') # True
# GET hello
world = r.get('hello')
print(world.decode()) # "world"