06.10.2016 Views

laravel-5

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Redis 439<br />

16 public function showProfile($id)<br />

17 {<br />

18 $user = Redis::get('user:profile:'.$id);<br />

19<br />

20 return view('user.profile', ['user' => $user]);<br />

21 }<br />

22 }<br />

Of course, as mentioned above, you may call any of the Redis commands on the Redis facade.<br />

Laravel uses magic methods to pass the commands to the Redis server, so simply pass the arguments<br />

the Redis command expects:<br />

1 Redis::set('name', 'Taylor');<br />

2<br />

3 $values = Redis::lrange('names', 5, 10);<br />

Alternatively, you may also pass commands to the server using the command method, which accepts<br />

the name of the command as its first argument, and an array of values as its second argument:<br />

1 $values = Redis::command('lrange', ['name', 5, 10]);<br />

Using Multiple Redis Connections<br />

You may get a Redis instance by calling the Redis::connection method:<br />

1 $redis = Redis::connection();<br />

This will give you an instance of the default Redis server. If you are not using server clustering, you<br />

may pass the server name to the connection method to get a specific server as defined in your Redis<br />

configuration:<br />

1 $redis = Redis::connection('other');

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!