-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #225 from biocore/st_dh_redis_backend
Redis Backend for Global State in client
- Loading branch information
Showing
6 changed files
with
129 additions
and
137 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,3 +3,4 @@ psycopg2 | |
flask | ||
natsort | ||
pycryptodome | ||
redis-py |
Empty file.
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import json | ||
import redis | ||
|
||
|
||
class RedisCache: | ||
# System Banner Format: ["Blah blah blah", "primary"] | ||
SYSTEM_BANNER = "system_banner" | ||
|
||
def __init__(self): | ||
self.r = redis.Redis(host='localhost', | ||
port=6379, | ||
db=0, | ||
decode_responses=True) | ||
|
||
def __getitem__(self, key): | ||
val = self.r.get(key) | ||
if val is None: | ||
return None | ||
return json.loads(val) | ||
|
||
def get(self, key, default): | ||
val = self.r.get(key) | ||
if val is None: | ||
return default | ||
return json.loads(val) | ||
|
||
def __setitem__(self, key, value): | ||
self.r.set(key, json.dumps(value)) | ||
|
||
def __delitem__(self, key): | ||
self.r.delete(key) |
This file contains 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
Oops, something went wrong.