Repository: juspay/hyperswitch
File: crates/router/src/types/storage/revenue_recovery_redis_operation.rs (Rust)

Code before:
        };

        tracing::debug!(
            connector_customer_id = connector_customer_id,
            payment_id = payment_id.get_string_repr(),
            lock_acquired = %result,
            "Connector customer lock attempt"
        );

        Ok(result)
    }
    #[instrument(skip_all)]
    pub async fn update_connector_customer_lock_ttl(
        state: &SessionState,
        connector_customer_id: &str,
        exp_in_seconds: i64,
    ) -> CustomResult<bool, errors::StorageError> {
        let redis_conn =
            state
                .store
                .get_redis_conn()
                .change_context(errors::StorageError::RedisError(
                    errors::RedisError::RedisConnectionError.into(),
                ))?;

        let lock_key = format!("customer:{connector_customer_id}:status");

        let result: bool = match redis_conn
            .set_expiry(&lock_key.into(), exp_in_seconds)
            .await
        {
            Ok(_) => true,
            Err(error) => {
                tracing::error!(operation = "update_lock_ttl", err = ?error);
                false
            }
        };

        tracing::debug!(
            connector_customer_id = connector_customer_id,
            new_ttl_in_seconds = exp_in_seconds,
            ttl_updated = %result,
            "Connector customer lock TTL update with new expiry time"
        );

        Ok(result)
    }

    /// Unlock connector customer status
    #[instrument(skip_all)]
    pub async fn unlock_connector_customer_status(

Review comment (refactor):
Please move this logic to an inline function.` fn get_connector_customer_lock_key` or something.
Call this function everywhere else.

Code after:
            )
            .await
        {
            Ok(resp) => resp == SetnxReply::KeySet,
            Err(error) => {
                tracing::error!(operation = "lock_stream", err = ?error);
                false
            }
        };

        tracing::debug!(
            connector_customer_id = connector_customer_id,
            payment_id = payment_id.get_string_repr(),
            lock_acquired = %result,
            "Connector customer lock attempt"
        );

        Ok(result)
    }
    #[instrument(skip_all)]
    pub async fn update_connector_customer_lock_ttl(
        state: &SessionState,
        connector_customer_id: &str,
        exp_in_seconds: i64,
    ) -> CustomResult<bool, errors::StorageError> {
        let redis_conn =
            state
                .store
                .get_redis_conn()
                .change_context(errors::StorageError::RedisError(
                    errors::RedisError::RedisConnectionError.into(),
                ))?;

        let lock_key = Self::get_connector_customer_lock_key(connector_customer_id);

        let result: bool = redis_conn
            .set_expiry(&lock_key.into(), exp_in_seconds)
            .await
            .map_or_else(
                |error| {
                    tracing::error!(operation = "update_lock_ttl", err = ?error);
                    false
                },
                |_| true,
            );

        tracing::debug!(
            connector_customer_id = connector_customer_id,
            new_ttl_in_seconds = exp_in_seconds,
            ttl_updated = %result,
            "Connector customer lock TTL update with new expiry time"