|
@@ -1,12 +1,15 @@
|
|
|
# @Author : Rocky
|
|
|
# @File : InitController.py
|
|
|
# @Time : 2023/4/11 17:26
|
|
|
+import ssl
|
|
|
+
|
|
|
from django.http import HttpResponse
|
|
|
from django.views import View
|
|
|
|
|
|
from Model.models import Device_Info, SceneLog
|
|
|
from Object.RedisObject import RedisObject
|
|
|
from Object.ResponseObject import ResponseObject
|
|
|
+import redis
|
|
|
|
|
|
|
|
|
class InitView(View):
|
|
@@ -24,6 +27,8 @@ class InitView(View):
|
|
|
def validation(self, request_dict, operation):
|
|
|
if operation == 'health-check': # 负载均衡器健康检测接口
|
|
|
return self.health_check(request_dict)
|
|
|
+ elif operation == 'oci_redis_test':
|
|
|
+ return self.oci_redis_test(request_dict)
|
|
|
|
|
|
@staticmethod
|
|
|
def health_check(request_dict):
|
|
@@ -36,3 +41,29 @@ class InitView(View):
|
|
|
return response.json(0)
|
|
|
except Exception as e:
|
|
|
return HttpResponse(repr(e), status=500)
|
|
|
+
|
|
|
+ @staticmethod
|
|
|
+ def oci_redis_test(request_dict):
|
|
|
+ try:
|
|
|
+ key = request_dict.get('key', None)
|
|
|
+ value = request_dict.get('value', None)
|
|
|
+ response = ResponseObject()
|
|
|
+ redis_host = 'amaaaaaayszequiamxr7cdpparig3ptmytvde5vvnz6n7gceo4232sbhhlsa-p.redis.us-phoenix-1.oci.oraclecloud.com'
|
|
|
+
|
|
|
+ # 启用TLS的配置
|
|
|
+ ssl_context = ssl.create_default_context()
|
|
|
+
|
|
|
+ # 创建Redis连接
|
|
|
+ redis_client = redis.StrictRedis(
|
|
|
+ host=redis_host,
|
|
|
+ ssl=True,
|
|
|
+ ssl_cert_reqs=None
|
|
|
+ )
|
|
|
+ redis_client.set(key, value)
|
|
|
+ redis_value = redis_client.get(key)
|
|
|
+ res = {
|
|
|
+ 'redis_value': redis_value
|
|
|
+ }
|
|
|
+ return response.json(0, res)
|
|
|
+ except Exception as e:
|
|
|
+ return HttpResponse(repr(e), status=500)
|