PHP code example of samsmithkruz / redis-client-class

1. Go to this page and download the library: Download samsmithkruz/redis-client-class 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/ */

    

samsmithkruz / redis-client-class example snippets




$redis = new RedisClient(); // Default: 127.0.0.1:6379

$redis->insert('username', 'john_doe', 3600); // Store for 1 hour
echo $redis->select('username'); // Output: john_doe
$redis->update('username', 'jane_doe');
$redis->delete('username');

$redis->hash_insert('user:1', 'name', 'John Doe');
echo $redis->hash_select('user:1', 'name'); // Output: John Doe

$redis->push('queue', 'task_1');
$redis->push('queue', 'task_2');
echo $redis->pop('queue'); // Output: task_2

$redis->publish('news', 'Breaking News: PHP is awesome!');
$redis->subscribe('news', function ($redis, $channel, $message) {
    echo "Received on $channel: $message";
});

$redis->transaction(function ($tx) {
    $tx->set('balance', 1000);
    $tx->incrBy('balance', 500);
});