<commit_before><?php

/**
 * Socket server on Redis Extension
 *
 * Copyright 2021 秋水之冰 <<EMAIL>>
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

namespace Ext;

use Core\Lib\App;

/**
 * Class libSockOnRedis
 *
 * @package Ext
 */
class libSockOnRedis extends libSocket
{
    public App      $app;
    public \Redis   $redis;
    public libQueue $lib_queue;

    public bool $is_ws = false;

    public int $batch_size = 200;

    public string $proc_name = 'worker';

    public string $hash_sock_ol = 'socket:map';
    public string $hash_proc_ol = 'socket:proc';
    public string $list_msg_key = 'socket:msg:';

    public array $ws_handshake = [];

    /**
     * Registered handler class
     *
     * MUST expose methods:
     * onConnect(string sid, string proc): void
     * onHandshake(string sid, string proto): bool
     * onMessage(string sid, string msg): void (push to Redis)
     * onClose(string sid): void
     *
     * @var string handler class name
     * @var object handler class object
     */
    public string $handler_class;
    public object $handler_object;

    /**
     * libSvrOnRedis constructor.
     *
     * @param string $address
     * @param string $port
     * @param string $protocol
     */
    public function __construct(string $address, string $port, string $protocol = 'tcp')
    {
        $this->app = App::new();

        $this->setAddr($address, $port, $protocol);
        $this->proc_name = $protocol . ':' . $port . ':' . $this->app->hostname;
    }

    /**
     * Bind Redis instance
     *
     * @param \Redis $redis
     *
     * @return $this
     */
    public function bindRedis(\Redis $redis): self
    {
        $this->redis = &$redis;

        unset($redis);
        return $this;
    }

    /**
     * Set push message batch size
     *
     * @param int $batch_size
     *
     * @return $this
     */
    public function setBatchSize(int $batch_size): self
    {
        $this->batch_size = &$batch_size;

        unset($batch_size);
        return $this;
    }<commit_msg>Add bindQueue method<commit_after><?php

/**
 * Socket server on Redis Extension
 *
 * Copyright 2021 秋水之冰 <<EMAIL>>
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

namespace Ext;

use Core\Lib\App;

/**
 * Class libSockOnRedis
 *
 * @package Ext
 */
class libSockOnRedis extends libSocket
{
    public App      $app;
    public \Redis   $redis;
    public libQueue $lib_queue;

    public bool $is_ws = false;

    public int $batch_size = 200;

    public string $proc_name = 'worker';

    public string $hash_sock_ol = 'socket:map';
    public string $hash_proc_ol = 'socket:proc';
    public string $list_msg_key = 'socket:msg:';

    public array $ws_handshake = [];

    /**
     * Registered handler class
     *
     * MUST expose methods:
     * onConnect(string sid, string proc): void
     * onHandshake(string sid, string proto): bool
     * onMessage(string sid, string msg): void (push to Redis)
     * onClose(string sid): void
     *
     * @var string handler class name
     * @var object handler class object
     */
    public string $handler_class;
    public object $handler_object;

    /**
     * libSvrOnRedis constructor.
     *
     * @param string $address
     * @param string $port
     * @param string $protocol
     */
    public function __construct(string $address, string $port, string $protocol = 'tcp')
    {
        $this->app = App::new();

        $this->setAddr($address, $port, $protocol);
        $this->proc_name = $protocol . ':' . $port . ':' . $this->app->hostname;
    }

    /**
     * Bind Redis instance
     *
     * @param \Redis $redis
     *
     * @return $this
     */
    public function bindRedis(\Redis $redis): self
    {
        $this->redis = &$redis;

        unset($redis);
        return $this;
    }

    /**
     * Bind Queue instance
     *
     * @param libQueue $queue
     *
     * @return $this
     */
    public function bindQueue(libQueue $queue): self
    {
        $this->lib_queue = &$queue;

        unset($queue);
        return $this;
    }

    /**
     * Set push message batch size
     *
     * @param int $batch_size
     *
     * @return $this
     */
    public function setBatchSize(int $batch_size): self
    {
        $this->batch_size = &$batch_size;

        unset($batch_size);
        return $this;
    }
{'fraction_non_alphanumeric': 0.1132251445625816, 'fraction_numerical': 0.004103711994030965, 'mean_word_length': 2.437179487179487, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 22, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, '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': '4763442', 'n_tokens_mistral': 1640, 'n_tokens_neox': 1598, 'n_words': 512}