PHP code example of webpatser / laravel-resp3-cache

1. Go to this page and download the library: Download webpatser/laravel-resp3-cache library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

webpatser / laravel-resp3-cache example snippets


'redis' => [
    'client' => env('REDIS_CLIENT', 'resp3'),
    'default' => [
        'host' => env('REDIS_HOST', '127.0.0.1'),
        'port' => env('REDIS_PORT', 6379),
        'password' => env('REDIS_PASSWORD'),
        'database' => env('REDIS_DB', 0),
    ],
],

'stores' => [
    'resp3' => [
        'driver' => 'resp3',
        'connection' => 'cache',          // key in config/database.php redis
        'lock_connection' => 'default',
        'prefix' => env('CACHE_PREFIX', 'app:'),
    ],
],

'redis' => [
    'client' => 'resp3',
    'options' => [
        'features' => ['msetex' => false, 'delex' => 'auto'],
    ],
    'default' => [/* ... */],
],

'stores' => [
    'resp3' => [
        'driver' => 'resp3',
        'connection' => 'cache',
        'prefix' => env('CACHE_PREFIX', 'app:'),
        'client_tracking' => [
            'enabled' => env('RESP3_CLIENT_TRACKING', false),
            'mode' => 'optin',          // or 'bcast'
            'prefixes' => [],           // bcast only; default: the store prefix
            'noloop' => false,
            'local_store' => 'auto',    // 'array' | 'apcu'
            'local_ttl' => 60,          // seconds, upper bound for a local entry
            'max_entries' => 10000,
            'max_value_bytes' => 65536, // larger values are never cached locally
            'max_bytes' => 33554432,    // array store: key plus value bytes, 32 MiB
        ],
    ],
],

'redis' => [
    'client' => 'resp3',
    'options' => [
        'cluster' => 'redis',
    ],
    'clusters' => [
        'default' => [
            ['host' => env('REDIS_HOST', '127.0.0.1'), 'port' => 6379],
            ['host' => env('REDIS_HOST_2', '127.0.0.1'), 'port' => 6380],
            ['host' => env('REDIS_HOST_3', '127.0.0.1'), 'port' => 6381],
        ],
        'options' => [
            'timeout' => 2,
            'cluster_read_replicas' => env('REDIS_CLUSTER_READ_REPLICAS', false),
        ],
    ],
],

Cache::put('{user:42}.profile', $profile);
Cache::put('{user:42}.cart',    $cart);
Cache::many(['{user:42}.profile', '{user:42}.cart']);  // one round trip

use Illuminate\Support\Facades\Redis;

Redis::subscribe(['user-events'], function (string $message, string $channel) {
    echo "[$channel] $message\n";
});

Redis::psubscribe(['user.*'], function (string $message, string $channel, string $pattern) {
    // ...
});

use Illuminate\Support\Facades\Redis;

// Subscriber: every channel must hash to the same slot. Use {hash tag}
// syntax to colocate them, exactly like multi-key MGET / MSET.
Redis::connection()->ssubscribe(
    ['orders.{user42}.created', 'orders.{user42}.updated'],
    function (string $message, string $channel) {
        // ...
    },
);

// Publisher: route via SPUBLISH (not PUBLISH) so the message lands on
// the same shard as the subscribers.
Redis::connection()->command('SPUBLISH', ['orders.{user42}.created', $payload]);

'redis' => [
    'client' => 'resp3',
    'options' => [
        'replication' => 'sentinel',
        'service'     => env('REDIS_SENTINEL_SERVICE', 'mymaster'),
        'sentinel_password' => env('REDIS_SENTINEL_PASSWORD'),
        'password' => env('REDIS_PASSWORD'),
        'database' => 0,
        'timeout'  => 0.5,
    ],
    'default' => [
        ['host' => env('REDIS_SENTINEL_1_HOST'), 'port' => 26379],
        ['host' => env('REDIS_SENTINEL_2_HOST'), 'port' => 26379],
        ['host' => env('REDIS_SENTINEL_3_HOST'), 'port' => 26379],
    ],
],

'options' => [
    'replication' => 'sentinel',
    'service'     => env('REDIS_SENTINEL_SERVICE', 'mymaster'),
    'sentinel_read_replicas' => env('REDIS_SENTINEL_READ_REPLICAS', false),
    // ...
],
bash
# Install the C extension first (PHP 8.4+, ext-resp3 ^0.2)
pie install webpatser/php-resp3:^0.2

# Then this Laravel package
composer