소스 검색

回滚测试oci Redis集群代码

locky 1 년 전
부모
커밋
c92628db4e
3개의 변경된 파일24개의 추가작업 그리고 39개의 파일을 삭제
  1. 0 9
      AnsjerPush/us_config/formal_config.py
  2. 3 18
      Controller/InitController.py
  3. 21 12
      Object/RedisObject.py

+ 0 - 9
AnsjerPush/us_config/formal_config.py

@@ -21,15 +21,6 @@ PUSH_BUCKET = 'foreignpush'                                # 推送存储桶
 
 # redis节点
 REDIS_ADDRESS = '10.60.1.113'
-REDIS_PASSWORD = '012bzaKUhleHc2645465'
-STARTUP_NODES = [
-    {'host': '10.60.1.113', 'port': 6379},
-    {'host': '10.60.1.119', 'port': 6379},
-    {'host': '10.60.1.52', 'port': 6379},
-    {'host': '10.60.1.107', 'port': 6379},
-    {'host': '10.60.1.24', 'port': 6379},
-    {'host': '10.60.1.201', 'port': 6379},
-]
 
 APNS_MODE = 'prod'
 

+ 3 - 18
Controller/InitController.py

@@ -8,7 +8,7 @@ import time
 from django.http import HttpResponse
 from django.views import View
 from redis.connection import SSLConnection
-from AnsjerPush.config import LOGGER
+
 from Model.models import Device_Info, SceneLog, EquipmentInfo1
 from Object.RedisObject import RedisObject
 from Object.ResponseObject import ResponseObject
@@ -39,9 +39,7 @@ class InitView(View):
     def health_check(request_dict):
         try:
             redis_obj = RedisObject()
-            LOGGER.info('打印1')
             redis_obj.set_data('health_check', 1)
-            LOGGER.info('打印2')
             response = ResponseObject()
             Device_Info.objects.filter().values('id').first()
             SceneLog.objects.filter().values('id').first()
@@ -51,23 +49,10 @@ class InitView(View):
 
     @staticmethod
     def oci_redis_test(request_dict):
-        response = ResponseObject()
         try:
             key = request_dict.get('key', None)
             value = request_dict.get('value', None)
-
-            # import rediscluster
-            # from rediscluster import ClusterConnectionPool
-            # password = '012bzaKUhleHc2645465'
-            # startup_nodes = [
-            #     {"host": "10.60.1.113", "port": 6379},
-            # ]
-            # pool = ClusterConnectionPool(startup_nodes=startup_nodes, password=password)
-            # r = rediscluster.RedisCluster(connection_pool=pool)
-            # r.ping()
-            # r.set(name=key, value=value, ex=60)
-            # redis_value = r.get(name=key)
-
+            response = ResponseObject()
             redis_obj = RedisObject()
             redis_obj.set_data(key, value, 60)
             redis_value = redis_obj.get_data(key)
@@ -76,7 +61,7 @@ class InitView(View):
             }
             return response.json(0, res)
         except Exception as e:
-            return response.json(500, 'error_line:{}, error_msg:{}'.format(e.__traceback__.tb_lineno, repr(e)))
+            return HttpResponse(repr(e), status=500)
 
     @staticmethod
     def oci_redis_test_2(request_dict):

+ 21 - 12
Object/RedisObject.py

@@ -1,6 +1,4 @@
 import redis
-import rediscluster
-from rediscluster import ClusterConnectionPool
 from AnsjerPush.config import REDIS_ADDRESS, CONFIG_INFO, CONFIG_US
 
 # 本地调试把注释打开
@@ -11,22 +9,33 @@ class RedisObject:
 
     def __init__(self, db=0):
         if CONFIG_INFO == CONFIG_US:
-            from AnsjerPush.config import STARTUP_NODES, REDIS_PASSWORD
-            pool = ClusterConnectionPool(startup_nodes=STARTUP_NODES, password=REDIS_PASSWORD, max_connections=100)
-            self.CONN = rediscluster.RedisCluster(connection_pool=pool)
+            password = '012bzaKUhleHc2645465'
+            pool = redis.ConnectionPool(host=REDIS_ADDRESS, password=password, port=6379, db=db)
         else:
             pool = redis.ConnectionPool(host=REDIS_ADDRESS, port=6379, db=db)
-            self.CONN = redis.Redis(connection_pool=pool)
+        self.CONN = redis.Redis(connection_pool=pool)
 
     def set_data(self, key, val, expire=0):
-        self.CONN.set(key, val)
-        if expire > 0:
-            self.CONN.expire(key, expire)
+        try:
+            self.CONN.set(key, val)
+            if expire > 0:
+                self.CONN.expire(key, expire)
+        except Exception as e:
+            return False
+        else:
+            return True
 
     def get_data(self, key):
-        val = self.CONN.get(key)
-        if val:
-            return val.decode('utf-8')
+        try:
+            val = self.CONN.get(key)
+        except Exception as e:
+            print(repr(e))
+            return False
+        else:
+            if val:
+                return val.decode('utf-8')
+            else:
+                return False
 
     def del_data(self, key):
         try: