File tree Expand file tree Collapse file tree 2 files changed +48
-38
lines changed
content/develop/clients/php
local_examples/client-specific/php Expand file tree Collapse file tree 2 files changed +48
-38
lines changed Original file line number Diff line number Diff line change @@ -40,51 +40,19 @@ composer require predis/predis
4040Connect to a locally-running server on the standard port (6379)
4141with the following code:
4242
43- ``` php
44- <?php
45-
46- require 'vendor/autoload.php';
47-
48- use Predis\Client as PredisClient;
49-
50- $r = new PredisClient([
51- 'scheme' => 'tcp',
52- 'host' => '127.0.0.1',
53- 'port' => 6379,
54- 'password' => '',
55- 'database' => 0,
56- ]);
57- ```
43+ {{< clients-example set="landing" step="connect" lang_filter="PHP" >}}
44+ {{< /clients-example >}}
5845
5946Store and retrieve a simple string to test the connection:
6047
61- ``` php
62- echo $r->set('foo', 'bar'), PHP_EOL;
63- // >>> OK
64-
65- echo $r->get('foo'), PHP_EOL;
66- // >>> bar
67- ```
48+ {{< clients-example set="landing" step="set_get_string" lang_filter="PHP" >}}
49+ {{< /clients-example >}}
6850
6951Store and retrieve a [ hash] ({{< relref "/develop/data-types/hashes" >}})
7052object:
7153
72- ``` php
73- $r->hset('user-session:123', 'name', 'John');
74- $r->hset('user-session:123', 'surname', 'Smith');
75- $r->hset('user-session:123', 'company', 'Redis');
76- $r->hset('user-session:123', 'age', 29);
77-
78- echo var_export($r->hgetall('user-session:123')), PHP_EOL;
79- /* >>>
80- array (
81- 'name' => 'John',
82- 'surname' => 'Smith',
83- 'company' => 'Redis',
84- 'age' => '29',
85- )
86- */
87- ```
54+ {{< clients-example set="landing" step="set_get_hash" lang_filter="PHP" >}}
55+ {{< /clients-example >}}
8856
8957## More information
9058
Original file line number Diff line number Diff line change 1+ // EXAMPLE: landing
2+ // BINDER_ID php-landing
3+ // STEP_START connect
4+ <?php
5+
6+ require 'vendor/autoload.php ' ;
7+
8+ use Predis \Client as PredisClient ;
9+
10+ $ r = new PredisClient ([
11+ 'scheme ' => 'tcp ' ,
12+ 'host ' => '127.0.0.1 ' ,
13+ 'port ' => 6379 ,
14+ 'password ' => '' ,
15+ 'database ' => 0 ,
16+ ]);
17+ // STEP_END
18+
19+ // STEP_START set_get_string
20+ echo $ r ->set ('foo ' , 'bar ' ), PHP_EOL ;
21+ // >>> OK
22+
23+ echo $ r ->get ('foo ' ), PHP_EOL ;
24+ // >>> bar
25+ // STEP_END
26+
27+ // STEP_START set_get_hash
28+ $ r ->hset ('user-session:123 ' , 'name ' , 'John ' );
29+ $ r ->hset ('user-session:123 ' , 'surname ' , 'Smith ' );
30+ $ r ->hset ('user-session:123 ' , 'company ' , 'Redis ' );
31+ $ r ->hset ('user-session:123 ' , 'age ' , 29 );
32+
33+ echo var_export ($ r ->hgetall ('user-session:123 ' )), PHP_EOL ;
34+ /* >>>
35+ array (
36+ 'name' => 'John',
37+ 'surname' => 'Smith',
38+ 'company' => 'Redis',
39+ 'age' => '29',
40+ )
41+ */
42+ // STEP_END
You can’t perform that action at this time.
0 commit comments