<commit_before><?php

namespace Illuminate\Foundation\Testing\Concerns;

use Illuminate\Redis\RedisManager;

trait InteractsWithRedis
{
    /**
     * Indicate connection failed if redis is not available.
     *
     * @var bool
     */
    private static $connectionFailedOnceWithDefaultsSkip = false;

    /**
     * Redis manager instance.
     *
     * @var \Illuminate\Redis\RedisManager[]
     */
    private $redis;

    /**
     * Setup redis connection.
     *
     * @return void
     */
    public function setUpRedis()
    {
        if (static::$connectionFailedOnceWithDefaultsSkip) {
            $this->markTestSkipped('Trying default host/port failed, please set environment variable REDIS_HOST & REDIS_PORT to enable '.__CLASS__);

            return;
        }

        $this->configureConnections();

        try {
            $this->redis['predis']->connection()->flushdb();
        } catch (\Exception $e) {
            $host = getenv('REDIS_HOST') ?: '127.0.0.1';
            $port = getenv('REDIS_PORT') ?: 6379;

            if ($host === '127.0.0.1' && $port === 6379 && getenv('REDIS_HOST') === false) {
                $this->markTestSkipped('Trying default host/port failed, please set environment variable REDIS_HOST & REDIS_PORT to enable '.__CLASS__);
                static::$connectionFailedOnceWithDefaultsSkip = true;

                return;
            }
        }
    }

    public function configureConnections()
    {
        if (!$this->redis) {
            $host = getenv('REDIS_HOST') ?: '127.0.0.1';
            $port = getenv('REDIS_PORT') ?: 6379;

            foreach ($this->redisDriverProvider() as $driver) {
                $this->redis[$driver[0]] = new RedisManager($driver[0], [
                    'cluster' => false,
                    'default' => [
                        'host' => $host,
                        'port' => $port,
                        'database' => 5,
                        'timeout' => 0.5,
                    ],
                ]);

                $this->redis[$driver[0]. '-prefixed'] = new RedisManager($driver[0], [
                    'cluster' => false,
                    'default' => [
                        'host' => $host,
                        'port' => $port,
                        'options' => ['prefix' => 'laravel:'],
                        'database' => 5,
                        'timeout' => 0.5,
                    ],
                ]);
            }
        }
    }

    /**
     * Returns the connections for use as dataProvider
     */
    public function redisConnections()
    {
        $connections = [];
        $this->configureConnections();

        foreach ($this->redis as $driver => $redis) {
            $connections[$driver] = [$redis->connection()];
        }

        return $connections;
    }

    /**
     * Teardown redis connection.
     *
     * @return void
     */
    public function tearDownRedis()
    {<commit_msg>formatting<commit_after><?php

namespace Illuminate\Foundation\Testing\Concerns;

use Illuminate\Redis\RedisManager;

trait InteractsWithRedis
{
    /**
     * Indicate connection failed if redis is not available.
     *
     * @var bool
     */
    private static $connectionFailedOnceWithDefaultsSkip = false;

    /**
     * Redis manager instance.
     *
     * @var \Illuminate\Redis\RedisManager[]
     */
    private $redis;

    /**
     * Setup redis connection.
     *
     * @return void
     */
    public function setUpRedis()
    {
        if (static::$connectionFailedOnceWithDefaultsSkip) {
            $this->markTestSkipped('Trying default host/port failed, please set environment variable REDIS_HOST & REDIS_PORT to enable '.__CLASS__);

            return;
        }

        $this->configureConnections();

        try {
            $this->redis['predis']->connection()->flushdb();
        } catch (\Exception $e) {
            $host = getenv('REDIS_HOST') ?: '127.0.0.1';
            $port = getenv('REDIS_PORT') ?: 6379;

            if ($host === '127.0.0.1' && $port === 6379 && getenv('REDIS_HOST') === false) {
                $this->markTestSkipped('Trying default host/port failed, please set environment variable REDIS_HOST & REDIS_PORT to enable '.__CLASS__);
                static::$connectionFailedOnceWithDefaultsSkip = true;

                return;
            }
        }
    }

    public function configureConnections()
    {
        if (! $this->redis) {
            $host = getenv('REDIS_HOST') ?: '127.0.0.1';
            $port = getenv('REDIS_PORT') ?: 6379;

            foreach ($this->redisDriverProvider() as $driver) {
                $this->redis[$driver[0]] = new RedisManager($driver[0], [
                    'cluster' => false,
                    'default' => [
                        'host' => $host,
                        'port' => $port,
                        'database' => 5,
                        'timeout' => 0.5,
                    ],
                ]);

                $this->redis["{$driver[0]}-prefixed"] = new RedisManager($driver[0], [
                    'cluster' => false,
                    'default' => [
                        'host' => $host,
                        'port' => $port,
                        'options' => ['prefix' => 'laravel:'],
                        'database' => 5,
                        'timeout' => 0.5,
                    ],
                ]);
            }
        }
    }

    /**
     * Returns the connections for use as dataProvider.
     */
    public function redisConnections()
    {
        $connections = [];
        $this->configureConnections();

        foreach ($this->redis as $driver => $redis) {
            $connections[$driver] = [$redis->connection()];
        }

        return $connections;
    }

    /**
     * Teardown redis connection.
     *
     * @return void
     */
    public function tearDownRedis()
    {
{'fraction_non_alphanumeric': 0.13746402573218217, 'fraction_numerical': 0.013543253766717453, 'mean_word_length': 1.5023295213892418, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 59, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 6, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3402542', 'n_tokens_mistral': 1715, 'n_tokens_neox': 1625, 'n_words': 325}