<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                合規國際互聯網加速 OSASE為企業客戶提供高速穩定SD-WAN國際加速解決方案。 廣告
                [TOC] # Redis ## 簡介 ``` // 可以通過 Composer 安裝`predis/predis`擴展包 composer require predis/predis ``` 也可以通過 PECL 安裝[PhpRedis](https://github.com/phpredis/phpredis)PHP 擴展。 ### 配置 ``` // 配置文件 config/database.php 'redis' => [ 'client' => 'predis', 'default' => [ 'host' => env('REDIS_HOST', '127.0.0.1'), 'password' => env('REDIS_PASSWORD', null), 'port' => env('REDIS_PORT', 6379), 'database' => env('REDIS_DB', 0), ], 'cache' => [ 'host' => env('REDIS_HOST', '127.0.0.1'), 'password' => env('REDIS_PASSWORD', null), 'port' => env('REDIS_PORT', 6379), 'database' => env('REDIS_CACHE_DB', 1), ], ], ``` ### 集群配置 ``` // 使用 clusters 鍵定義集群 'redis' => [ 'client' => 'predis', 'clusters' => [ 'default' => [ [ 'host' => env('REDIS_HOST', 'localhost'), 'password' => env('REDIS_PASSWORD', null), 'port' => env('REDIS_PORT', 6379), 'database' => 0, ], ], ], ], // 使用 Redis 原生集群,需要在配置文件下的 options 鍵中設置 'redis' => [ 'client' => 'predis', 'options' => [ 'cluster' => 'redis', ], 'clusters' => [ // ... ], ], ``` ### Predis ``` // Predis 還支持為每個 Redis 服務器定義其它的鏈接參數 connection parameters 。 // https://github.com/nrk/predis/wiki/Connection-Parameters 'default' => [ 'host' => env('REDIS_HOST', 'localhost'), 'password' => env('REDIS_PASSWORD', null), 'port' => env('REDIS_PORT', 6379), 'database' => 0, 'read_write_timeout' => 60, ], ``` ### PhpRedis ``` // 要使用 PhpRedis 擴展,需要將配置文件 config/database.php 中 Redis 配置的 client 選項修改為 phpredis 'redis' => [ 'client' => 'phpredis', // 其余的Redis配置... ], // PhpRedis 還支持幾個額外的連接參數: persistent, prefix, read_timeout 和 timeout 。 'default' => [ 'host' => env('REDIS_HOST', 'localhost'), 'password' => env('REDIS_PASSWORD', null), 'port' => env('REDIS_PORT', 6379), 'database' => 0, 'read_timeout' => 60, ], ``` ## Redis 交互 ``` // 通過調用 Redis facade 上的各種方法來與 Redis 交互。 <?php namespace App\Http\Controllers; use App\Http\Controllers\Controller; use Illuminate\Support\Facades\Redis; class UserController extends Controller { /** * 顯示給定用戶的配置文件。 * * @param int $id * @return Response */ public function showProfile($id) { $user = Redis::get('user:profile:'.$id); return view('user.profile', ['user' => $user]); } } Redis::set('name', 'Taylor'); $values = Redis::lrange('names', 5, 10); // 使用 command 方法將命令傳遞給服務器,它接受命令的名稱作為其第一個參數,并將值的數組作為其第二個參數 $values = Redis::command('lrange', ['name', 5, 10]); ``` ### 使用多個 Redis 連接 ``` $redis = Redis::connection(); // 傳遞連接或者集群名稱給 connection 方法來獲取在 Redis 配置中特定服務或集群 $redis = Redis::connection('my-connection'); ``` ### 管道命令 當你需要在一個操作中給服務器發送很多命令時,推薦你使用管道命令。`pipeline`方法接受一個 Redis 實例的`閉包`。你可以將所有的命令發送給 Redis 實例,它們都會在一個操作中執行完成: ``` // 當你需要在一個操作中給服務器發送很多命令時,推薦你使用管道命令。 Redis::pipeline(function ($pipe) { for ($i = 0; $i < 1000; $i++) { $pipe->set("key:$i", $i); } }); ``` ## 發布與訂閱 ``` // 使用 subscribe 方法設置頻道監聽器,在 Artisan 命令調用 <?php namespace App\Console\Commands; use Illuminate\Console\Command; use Illuminate\Support\Facades\Redis; class RedisSubscribe extends Command { /** * 控制臺命令的名稱和簽名。 * * @var string */ protected $signature = 'redis:subscribe'; /** * 控制臺命令說明。 * * @var string */ protected $description = 'Subscribe to a Redis channel'; /** * 執行控制臺命令。 * * @return mixed */ public function handle() { Redis::subscribe(['test-channel'], function ($message) { echo $message; }); } } // 使用 publish 方法將消息發布到頻道 Route::get('publish', function () { // 路由... Redis::publish('test-channel', json_encode(['foo' => 'bar'])); }); ``` ### 通配符訂閱 ``` Redis::psubscribe(['*'], function ($message, $channel) { echo $message; }); Redis::psubscribe(['users.*'], function ($message, $channel) { echo $message; }); ```
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看