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) |
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
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 |
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
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" |