def user_label_to_redis(ds, **kwargs): label_list = { 'lab_new_user': 1, 'lab_login_without_orders': 2, 'lab_login_have_orders': 3, 'lab_cancel_ge_finish': 4 } query = """ SELECT user_id, lab_new_user, lab_login_without_orders, lab_login_have_orders, lab_cancel_ge_finish, phone_number FROM dashboard.oride_user_label WHERE dt='{dt}' """.format(dt=ds) cursor = get_hive_cursor() cursor.execute(query) results = cursor.fetchall() redis_conn = RedisHook(redis_conn_id='redis_user_lab').get_conn() expire_time = 86400 for user_id, lab_new_user, lab_login_without_orders, lab_login_have_orders, lab_cancel_ge_finish, phone_number in results: list = [] if lab_new_user == True: list.append(label_list['lab_new_user']) if lab_login_without_orders == True: list.append(label_list['lab_login_without_orders']) if lab_login_have_orders == True: list.append(label_list['lab_login_have_orders']) if lab_cancel_ge_finish == True: list.append(label_list['lab_cancel_ge_finish']) if len(list): redis_key = 'user_tag_%s' % phone_number redis_conn.set(redis_key, json.dumps(list), ex=expire_time) logging.info('user_id:%s, lab_list:%s, key:%s, phone_number:%s' % (user_id, json.dumps(list), redis_key, phone_number)) cursor.close()
def set_redis_data(data, **kwargs): prefixRunId = getUniqueRunId(kwargs) redis_conn = RedisHook(redis_conn_id='redis_default').get_conn() redis_conn.set(prefixRunId, json.dumps(data))