def get(self, request, redis_name, value_db_id, key): from public.redis_api import get_cl from public.data_view import get_value logs.info('get value: redis_name={0}, db={1}, key={2}'.format( redis_name, value_db_id, key)) cl = get_cl(redis_name, int(value_db_id)) value_dict = {'code': 0, 'msg': '', 'data': ''} if cl.exists(key): value = '' if request.GET.get("type", None) == 'ttl': value = cl.ttl(key) if value is None: value = -1 logs.info( 'get key ttl: redis_name={0}, db={1}, key={2}, ttl={3}'. format(redis_name, value_db_id, key, value)) else: try: value = get_value(key, int(value_db_id), cl) except Exception as e: logs.error( 'get value is error: redis_name:{0}, key:{1}, db:{2}, cl:{3}, error_info:{4}' .format(redis_name, key, value_db_id, cl, e)) value_dict['code'] = 1 value_dict['data'] = value else: logs.warning( 'key is not exists: redis_name={0}, db={1}, key={2}'.format( redis_name, value_db_id, key)) value_dict['code'] = 1 return JsonResponse(value_dict, safe=False)
def get(self, request, redis_name, edit_db_id): from public.redis_api import get_cl from public.data_view import get_value cl = get_cl(redis_name, int(edit_db_id)) key = request.GET.get('key', None) if cl.exists(key): value = get_value(key, int(edit_db_id), cl) if cl.type(key) == 'list': value_list = [] num = 0 for i in value['value']: value_dict = {str(num): i} num += 1 value_list.append(value_dict) value['value'] = value_list return render( request, 'edit.html', { 'db_num': 'db' + str(edit_db_id), 'redis_name': redis_name, 'data': value, })
def get(self, request, redis_name, value_db_id, key): from public.redis_api import get_cl from public.data_view import get_value cl, cur_server_index, cur_db_index = get_cl(redis_name, int(value_db_id)) value_dict = {'code': 0, 'msg': '', 'data': ''} if cl.exists(key): value = '' if request.GET.get("type", None) == 'ttl': value = cl.ttl(key) if value is None: value = -1 else: try: value = get_value(key, cur_server_index, cur_db_index, cl) except Exception as e: logs.error(e) value_dict['code'] = 1 value_dict['data'] = value else: value_dict['code'] = 1 return JsonResponse(value_dict, safe=False)
def post(self, request): from public.data_change import ChangeData from loginfo.models import OperationInfo from public.redis_api import get_cl from public.data_view import get_value redis_name = request.POST.get('redis_name', None) db_id = request.POST.get('db_id', None) key = request.POST.get('key', None) cl = get_cl(redis_name, int(db_id)) old_data = get_value(key, int(db_id), cl) db = OperationInfo( username=request.user.username, server=redis_name, db=db_id, key=key, old_value=old_data, type='del', ) db.save() if key: ch_data = ChangeData(redis_name=redis_name, db_id=db_id) if ch_data.delete_key(key=key): data = { 'code': 0, 'msg': 'KEY: ' + key + ' is Success', 'data': '' } return JsonResponse(data) data = {'code': 1, 'msg': 'KEY: ' + key + ' is Failed', 'data': ''} return JsonResponse(data)
def post(self, request, redis_name, edit_db_id): from public.data_change import ChangeData from public.redis_api import get_cl from public.data_view import get_value from loginfo.models import OperationInfo cl = get_cl(redis_name, int(edit_db_id)) ch_data = ChangeData(redis_name=redis_name, db_id=edit_db_id) key = request.GET.get('key', None) post_key_type = request.POST.get('Type', None) old_data = get_value(key, int(edit_db_id), cl) if post_key_type == 'string': post_value = request.POST.get('value', None) ch_data.edit_value(key=key, value=None, new=post_value, score=None) elif post_key_type == 'zset': score = request.POST.get('Score', None) value = request.POST.get('Value', None) old_value = request.POST.get('Old_Value', None) ch_data.edit_value(key=key, value=old_value, new=value, score=score) elif post_key_type == 'set': value = request.POST.get('Value', None) old_value = request.POST.get('Old_Value', None) ch_data.edit_value(key=key, value=old_value, new=value, score=None) elif post_key_type == 'hash': value_key = request.POST.get('Key', None) value = request.POST.get('Value', None) ch_data.edit_value(key=key, value=value_key, new=value, score=None) elif post_key_type == 'list': index = request.POST.get('Index', None) value = request.POST.get('Value', None) ch_data.edit_value(key=key, value=index, new=value, score=None) data = get_value(key, int(edit_db_id), cl) if cl.type(key) == 'list': value_list = [] num = 0 for i in data['value']: value_dict = {str(num): i} num += 1 value_list.append(value_dict) data['value'] = value_list db = OperationInfo( username=request.user.username, server=redis_name, db='db' + edit_db_id, key=key, old_value=old_data, value=data, type='edit', ) db.save() return render( request, 'edit.html', { 'db_num': 'db' + str(edit_db_id), 'redis_name': redis_name, 'data': data })
def get(self, request, redis_name, value_db_id): from public.redis_api import get_cl from public.data_view import get_value key = request.GET.get('key', None) logs.info('get value: redis_name={0}, db={1}, key={2}'.format( redis_name, value_db_id, key)) cl = get_cl(redis_name, int(value_db_id)) value_dict = {'code': 0, 'msg': '', 'data': ''} keyobj = None isCmd = False try: keyobj = json.loads(key) if keyobj.has_key('cmd'): isCmd = True except Exception as e: pass finally: pass if isCmd: cmdList = keyobj.get('cmd').split() cmdList[0] = cmdList[0].upper() logs.info('execute: cmd={0}'.format(" ".join(cmdList))) try: res = cl.execute_command(*cmdList) except Exception as e: res = str(e) logs.info('execute response={0}'.format(res)) if isinstance(res, basestring): res = res.replace("\r\n", "\n").strip("\n").split("\n") resinfo = { "db": int(value_db_id), "key": " ".join(cmdList), "value": json.dumps(res), "ttl": -1, "type": "string" } #{'$response':res} #{"encoding":"","db":0,"value":"aa","key":"a a","ttl":-1,"type":"string","size":2} value_dict['data'] = resinfo return JsonResponse(value_dict, safe=False) if cl.exists(key): value = {} if request.GET.get("type", None) == 'ttl': ttl = cl.ttl(key) if ttl is None: ttl = -1 logs.info( 'get key ttl: redis_name={0}, db={1}, key={2}, ttl={3}'. format(redis_name, value_db_id, key, ttl)) value = { "db": value_db_id, "key": key, "value": ttl, "ttl": ttl, "type": "long" } else: try: value = get_value(key, int(value_db_id), cl) except Exception as e: logs.error( 'get value is error: redis_name:{0}, key:{1}, db:{2}, cl:{3}, error_info:{4}' .format(redis_name, key, value_db_id, cl, e)) value_dict['code'] = 1 if value.has_key('value'): value['value'] = json.dumps(value.get('value')) value_dict['data'] = value else: logs.warning( 'key is not exists: redis_name={0}, db={1}, key={2}'.format( redis_name, value_db_id, key)) value_dict['code'] = 1 return JsonResponse(value_dict, safe=False)