반응형
Docker 관련 포스팅 링크
docker Image 설치
$ docker pull redis:alpine
docker 실행
$ docker run --name my-redis -p 6379:6379 -v redisFolder:/data -d redis:alpine redis-server
Host에서 Redis 접속
$ redis-cli -h localhost
Djagno 환경
views.py
import redis
import json
from django.shortcuts import render
from django.http import HttpResponse
from django.views.generic import View
from django.views.decorators.csrf import csrf_exempt
from django.utils.decorators import method_decorator
import logging
logger = logging.getLogger('django.server')
# Create your views here.
class redisInstance:
def __init__(self):
self.redis = redis.Redis()
self.EXPIRE_TIME = 30 # 30초
def get(self, key):
return self.redis.get(key).decode()
def setex(self, key, value):
self.redis.setex(key, self.EXPIRE_TIME ,value)
@method_decorator(csrf_exempt, name='dispatch')
class indexView(View):
def get(self, request, *args, **kwargs):
return HttpResponse("Get")
def post(self, request, *args, **kwargs):
try:
r = redisInstance()
req = json.loads(request.body)
key = req.get("key","")
value = req.get('value',"")
r.setex(key,value)
data = f"{key} / {value} / {r.get(key)}"
return HttpResponse(data)
except Exception as e:
logger.info(e)
return HttpResponse("Error")
반응형
'Study > WEB' 카테고리의 다른 글
AngularJS 시작하기 - 환경 구성 (1/3) (0) | 2022.10.09 |
---|---|
AngularJS에 대하여 알아보자 (0) | 2022.10.09 |
TypeScript 시작하기 - 환경 구성 (0) | 2022.10.03 |
TypeScript에 대하여 알아보자 (0) | 2022.10.03 |
Spring Boot + Kotlin의 모니터링 도구, Spring Actuator, Prometheus, Grafana (2/2) (0) | 2022.09.18 |
댓글