-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcacheHandler.py
More file actions
68 lines (53 loc) · 1.92 KB
/
Copy pathcacheHandler.py
File metadata and controls
68 lines (53 loc) · 1.92 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
import elasticache_auto_discovery
from pymemcache.client.hash import HashClient
import redis
import boto3
import config
class MemCacheHandler:
def __init__(self):
nodes = elasticache_auto_discovery.discover(config.cacheHandler['memchached_endpoint'])
nodes = map(lambda x: (x[1], int(x[2])), nodes)
self.cache_client = HashClient(nodes)
def push(self, key, val):
self.cache_client.set(key, val)
def pull(self, key):
return self.cache_client.get(key)
def delete(self, key):
self.cache_client.delete(key)
class RedisHandler:
def __init__(self):
self.cache_client = redis.Redis(host=config.cacheHandler['redis_endpoint'], port=6379, db=0)
def push(self, key, val):
self.cache_client.set(key, val)
def pull(self, key):
return self.cache_client.get(key)
def delete(self, key):
self.cache_client.delete(key)
class Boto3Handler:
def __init__(self):
session = boto3.Session(aws_access_key_id=config.cacheHandler['key'], aws_secret_access_key=config.cacheHandler['secret'])
self.cache_client = session.client('ecr', region_name='us-west-2')
self.repository_endpoint = config.cacheHandler['repository_endpoint']
def push(self, key, val):
self.cache_client.tag_resource(
resourceArn=self.repository_endpoint,
tags=[
{
'Key': key,
'Value': str(val)
},
]
)
def pull(self, key):
tags = self.cache_client.list_tags_for_resource(
resourceArn=self.repository_endpoint
)
for tag in tags['tags']:
if 'Key' in tag and tag['Key'] == key:
return tag['Value']
return '0'
def delete(self, key):
self.cache_client.untag_resource(
resourceArn=self.repository_endpoint,
tagKeys=[key]
)