def save_context_to_redis(params,
                          init_flag=False,
                          mode="multi_process",
                          del_flag=False):

    if params["next_option"] is None:
        delete_round_redis(params)
        return None

    redisConn = RedisConn()
    redis_ = redisConn.redis_conn
    if init_flag:
        try:

            customer_id = params['customer_id']

            redis_.set(customer_id + mode, json.dumps([params]))
        except Exception as e:
            return None

    else:
        try:
            customer_id = params['customer_id']

            value = json.loads(redis_.get(customer_id + mode))
            value.append(params)
            redis_.set(customer_id + mode, json.dumps(value))

        except Exception as e:
            return None
def change_syn(question):
    redisConn = RedisConn()
    redis_ = redisConn.redis_conn
    ws = [str(i.decode()) for i in redis_.lrange("synormy_of_next", 0, -1)]
    if question.strip() in ws:
        return "下一步"
    else:
        return question
Example #3
0
def test_redis(request):
    gm.update_keywords_from_question()
    exit()
    from chatbot.settings import RedisConn
    redisConn = RedisConn()
    r = redisConn.redis_conn
    res = r.get('bing')
    print(res)
    return HttpResponse(str(res))
def redis_push():
    redisConn = RedisConn()
    redis_ = redisConn.redis_conn
    l = [
        "go on", "GO ON", "继续", "下一步", "接着下一步", "接下来", "接着,下一步", "next",
        "next step", "go", "go to next"
    ]
    for e in l:
        redis_.lpush("synormy_of_next", str(e))
def get_last_round_time(params, mode="multi_process"):
    try:
        redisConn = RedisConn()
        redis_ = redisConn.redis_conn
        t = redis_.get("{}_{}_timestamp".format(params["data"]['customer_id'],
                                                mode))
        return float(t)
    except Exception as e:
        return -1
def fetch_context_from_redis(params, mode="multi_process"):
    try:
        customer_id = params['customer_id']
        redisConn = RedisConn()
        redis_ = redisConn.redis_conn
        value = redis_.get(customer_id + mode)
        return value
    except Exception as e:
        return None
def delete_round_redis(params, mode="multi_process"):
    try:

        customer_id = params['data']['customer_id']
        redisConn = RedisConn()
        redis_ = redisConn.redis_conn
        # a = json.dumps([params])
        redis_.delete(customer_id + mode)
    except Exception as e:
        return None
def save_time_to_redis(
    params,
    mode="multi_process",
):

    redisConn = RedisConn()
    redis_ = redisConn.redis_conn
    import time
    t = time.time()
    redis_.set("{}_{}_timestamp".format(params["data"]['customer_id'], mode),
               t)