Uname:Linux machinox-server 6.17.0-1013-aws #13~24.04.1-Ubuntu SMP Fri Apr 24 21:36:58 UTC 2026 aarch64

Base Dir : /var/www/machinox.in

User : root


403WebShell
403Webshell
Server IP : 13.235.167.51  /  Your IP : 216.73.217.116
Web Server : Apache
System : Linux machinox-server 6.17.0-1013-aws #13~24.04.1-Ubuntu SMP Fri Apr 24 21:36:58 UTC 2026 aarch64
User : root ( 0)
PHP Version : 8.2.29
Disable Function : NONE
MySQL : OFF  |  cURL : ON  |  WGET : ON  |  Perl : ON  |  Python : OFF  |  Sudo : ON  |  Pkexec : OFF
Directory :  /var/www/app.machinox.in/app/Services/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ Back ]     

Current File : /var/www/app.machinox.in/app/Services/RedisService.php
<?php

namespace App\Services;

use Illuminate\Support\Facades\Redis;

class RedisService
{
    protected $enabled = true; // You can control via env

    public function isEnabled(): bool
    {
        return $this->enabled && config('database.redis.default.host') !== null;
    }
    
    // 🔹 Key-Value operations
    public function set(string $key, mixed $value, int $ttl = 3600): void
    {
        Redis::setex($key, $ttl, is_array($value) ? json_encode($value) : $value);
    }

    public function get(string $key): mixed
    {
        $value = Redis::get($key);
        return $this->isJson($value) ? json_decode($value, true) : $value;
    }

    public function delete(string $key): void
    {
        Redis::del($key);
    }

    public function exists(string $key): bool
    {
        return Redis::exists($key) > 0;
    }

    // 🔹 List operations (Queue-like)

    /**
     * Push List Items (Queue)
     * $redis->pushToList('task_queue', ['id' => 1, 'task' => 'Send Email']);
     */
    public function pushToList(string $key, mixed $value, string $direction = 'right'): void
    {
        $value = is_array($value) ? json_encode($value) : $value;
        $direction === 'left'
            ? Redis::lpush($key, $value)
            : Redis::rpush($key, $value);
    }
    /**
     * Pop List Items (Queue)
     * $task = $redis->popFromList('task_queue');
     */
    public function popFromList(string $key, string $direction = 'left'): mixed
    {
        $value = $direction === 'left'
            ? Redis::lpop($key)
            : Redis::rpop($key);

        return $this->isJson($value) ? json_decode($value, true) : $value;
    }

    public function listLength(string $key): int
    {
        return Redis::llen($key);
    }

    /**
     *  🔹 Pub/Sub operations
     *  $redis->publish('chat-channel', ['user' => 'John', 'message' => 'Hello!']);
     *
     */
    public function publish(string $channel, mixed $message): void
    {
        Redis::publish($channel, is_array($message) ? json_encode($message) : $message);
    }
    /**
     * Subscriber (CLI command, daemon, etc):
     * ⚠️ Subscribing blocks the process, so use it in CLI scripts or queues.
     * $redis->subscribe('chat-channel', function ($message) {
     *     logger('New message: ' . print_r($message, true));
     * });
     */
    public function subscribe(array|string $channels, \Closure $callback): void
    {
        Redis::subscribe((array)$channels, function ($message) use ($callback) {
            $decoded = $this->isJson($message) ? json_decode($message, true) : $message;
            $callback($decoded);
        });
    }

    // 🔹 Set operations
    /**
     * Sets (No Duplicates)
     * $redis->addToSet('online_users', 'user123');
     */
    public function addToSet(string $key, mixed $value): void
    {
        Redis::sadd($key, is_array($value) ? json_encode($value) : $value);
    }

    /**
     * $onlineUsers = $redis->getSetMembers('online_users');
     */
    public function getSetMembers(string $key): array
    {
        return Redis::smembers($key);
    }

    /**
     *
     * $redis->removeFromSet('online_users', 'user123');
     */
    public function removeFromSet(string $key, mixed $value): void
    {
        Redis::srem($key, is_array($value) ? json_encode($value) : $value);
    }

    // 🔹 Helper
    private function isJson($string): bool
    {
        json_decode($string);
        return json_last_error() === JSON_ERROR_NONE;
    }
}

Youez - 2016 - github.com/yon3zu
LinuXploit