Skip to content

Commit

Permalink
use redis for pid lookup
Browse files Browse the repository at this point in the history
  • Loading branch information
cehbrecht committed Aug 22, 2024
1 parent 8a48a7d commit 0cd186e
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 1 deletion.
11 changes: 11 additions & 0 deletions docker/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,19 @@ services:
volumes:
- es_data:/usr/share/elasticsearch/data

redis:
image: redislabs/rejson:latest
container_name: redis
ports:
- "6379:6379"
volumes:
- redis_data:/data
command: ["redis-server", "--loadmodule", "/usr/lib/redis/modules/rejson.so"]

volumes:
rabbitmq_data:
driver: local
es_data:
driver: local
redis_data:
driver: local
2 changes: 2 additions & 0 deletions environment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ dependencies:
#- pyhandle >=1.2.1
- jsonschema-with-format
- dataclasses-json
# redis
- redis-py
# tests
- pytest
- sqlite
3 changes: 3 additions & 0 deletions piddiplatsch/handler/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from jsonschema import ValidationError
from piddiplatsch.exceptions import CheckError
from piddiplatsch.pidmaker import PidMaker
from piddiplatsch.pidlookup import PidLookup
from piddiplatsch.validator import validate

import logging
Expand Down Expand Up @@ -137,3 +138,5 @@ def publish(self, record):
handle = record.get("HANDLE")
pid_maker = PidMaker(self.dry_run)
pid_maker.register_handle(handle, record)
pid_lookup = PidLookup()
pid_lookup.set(handle, record)
31 changes: 31 additions & 0 deletions piddiplatsch/pidlookup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import redis
import json
import logging

LOGGER = logging.getLogger("piddiplatsch")


def PidLookup():
return RedisLookup()


class BaseLookup:
def set(self, name, record):
pass

def get(self, name):
pass


class RedisLookup(BaseLookup):
def __init__(self):
self.client = redis.Redis(host="localhost", port=6379)

def set(self, name, record):
LOGGER.info(f"stored record with name: {name}")
self.client.set(name, json.dumps(record))

def get(self, name):
stored_data = self.client.get(name)
record = json.loads(stored_data)
return record
3 changes: 2 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@ click
pika >=1.3.1
pyhandle >=1.2.1
jsonschema[format] >=4.21.1
dataclasses-json >=0.6.4
dataclasses-json >=0.6.4
redis >=5.0.9

0 comments on commit 0cd186e

Please sign in to comment.