예제 #1
0
    def check_expire_access_token(access_token):
        """
        check access token whether is validate; if it is, reset it's expire time
        :param access_token:
        :return:
        """
        token_user_key = key_maker.mk_token_username_key(access_token)
        session_tcp = ServiceMgrCacher().get_connection(US_SESSION_DA, RT_HASH_RING, token_user_key)

        result = user_session_select(session_tcp, [token_user_key])
        validate = True if result[token_user_key] else False
        if validate:
            # reset expire time
            params = {token_user_key: setting.ACCESS_TOKEN_EXPIRE}
            user_session_expire(session_tcp, params)
        return validate
예제 #2
0
    def test_session_insert_select_delete_update(self):
        KEY1 = random_str()
        VALUE1 = random_str()
        EXPIRE_TIME1 = 200

        SessionDATcp = ServiceMgrCacher().get_connection(ST_SESSION_DA,
                                                      rdm_type=RT_HASH_RING,
                                                      rdm_param=KEY1)
        self.assertEqual(SessionDATcp.ping(), "ping response!")

        params = {KEY1: [VALUE1, EXPIRE_TIME1]}
        self.assertTrue(user_session_insert(SessionDATcp, params))

        self.assertTrue(user_session_select(SessionDATcp, [KEY1]) == \
                        {KEY1: VALUE1})

        params = {KEY1: EXPIRE_TIME1}
        self.assertTrue(user_session_expire(SessionDATcp, params))

        self.assertTrue(user_session_delete(SessionDATcp, [KEY1]))

        self.assertTrue(user_session_select(SessionDATcp, [KEY1]) == \
                        {KEY1: None})