def add_sensitive_words(add_words_dict): status = False add_words_list = add_words_dict.keys() #step1: identify the words is not exist print 'add_words_list:', add_words_list exist_word_set = set() for add_word in add_words_list: if add_word: try: exist_mark = R_ADMIN.hexists(r_sensitive_words_key, add_word) except: exist_mark = 0 if exist_mark == 1: exist_word = add_word add_words_dict.pop(exist_word) exist_word_set.add(exist_word) #step2: add words(not have been exist) to redis if add_words_dict: try: R_ADMIN.hmset(r_sensitive_words_key, add_words_dict) status = True except: status = False #step3: return have been exist words dict if exist_word_set: exist_word_list = list(exist_word_set) else: exist_word_list = [] return status, exist_word_list
def delete_sensitive_words(delete_words_list): status = False #step1: identify the word exist #step2: delete th word no_exist_word_list = [] for word in delete_words_list: exist_mark = R_ADMIN.hexists(r_sensitive_words_key, word) if exist_mark == 1: R_ADMIN.hdel(r_sensitive_words_key, word) status = True else: no_exist_word_list.append(word) return status, no_exist_word_list
def modify_sensitive_words(modify_words_dict): status = False not_exist_word_list = [] #step1: identify the word exist for modify_word in modify_words_dict: exist_mark = R_ADMIN.hexists(r_sensitive_words_key, modify_word) if exist_mark == 0: modify_words_dict.pop(modify_word) not_exist_word_list.append(modify_word) #step2: modify sensitive word rank if modify_words_dict: #try: R_ADMIN.hmset(r_sensitive_words_key, modify_words_dict) status = True #except: # status = False #test print 'modify result:', modify_words_dict return status, not_exist_word_list