Skip to content

Commit 1ce9b68

Browse files
Merge pull request #1939 from redis/DOC-5544-enable-php-tces
DOC-5544 enable PHP tabbed code examples
2 parents bc65551 + fc92f93 commit 1ce9b68

File tree

5 files changed

+107
-2
lines changed

5 files changed

+107
-2
lines changed

config.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ tagManagerId = "GTM-TKZ6J9R"
4545
gitHubRepo = "https://github.com/redis/docs"
4646

4747
# Display and sort order for client examples
48-
clientsExamples = ["Python", "Node.js", "Java-Sync", "Java-Async", "Java-Reactive", "Go", "C#", "RedisVL"]
48+
clientsExamples = ["Python", "Node.js", "Java-Sync", "Java-Async", "Java-Reactive", "Go", "C#", "RedisVL", "PHP"]
4949
searchService = "/convai/api/search-service"
5050
ratingsService = "/docusight/api/rate"
5151

@@ -66,6 +66,7 @@ rdi_current_version = "1.12.3"
6666
"Go"={quickstartSlug="go"}
6767
"C#"={quickstartSlug="dotnet"}
6868
"RedisVL"={quickstartSlug="redis-vl"}
69+
"PHP"={quickstartSlug="php"}
6970

7071
# Markup
7172
[markup]

data/components/index.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
"nredisstack",
1111
"go_redis",
1212
"node_redis",
13+
"php",
1314
"redis_py",
1415
"jedis",
1516
"lettuce_async",

data/components/php.json

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"id": "php",
3+
"type": "client",
4+
"name": "Predis",
5+
"language": "PHP",
6+
"label": "PHP",
7+
"repository": {
8+
"git_uri": "https://github.com/predis/predis"
9+
},
10+
"examples": {
11+
"git_uri": "https://github.com/predis/predis",
12+
"path": "examples",
13+
"pattern": "*.php"
14+
}
15+
}

layouts/partials/tabs/wrapper.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
<input tabindex="1" type="radio" name="{{ $id }}" id="{{ $tid }}" data-lang="{{ $dataLang }}" class="radiotab w-0 h-0"
1818
{{ if eq $i 0 }}checked{{ end }}
1919
/>
20-
<label class="justify-left label ml-1.5 pt-3.5 px-1 pb-1 cursor-pointer text-sm text-center bg-redis-ink-900
20+
<label class="justify-left label ml-0.5 pt-3.5 px-1 pb-1 cursor-pointer text-sm text-center bg-redis-ink-900
2121
hover:text-redis-red-600 rounded rounded-mx transition duration-150 ease-in-out"
2222
title="Open example" for="{{ $tid }}">
2323
{{ if eq (index $tab "title") "redis-cli" }}

local_examples/php/DtStringTest.php

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
// EXAMPLE: set_tutorial
2+
<?php
3+
4+
require 'vendor/autoload.php';
5+
6+
use Predis\Client as PredisClient;
7+
8+
class DtStringTest
9+
// REMOVE_START
10+
extends PredisTestCase
11+
// REMOVE_END
12+
{
13+
public function testDtString() {
14+
$r = new PredisClient([
15+
'scheme' => 'tcp',
16+
'host' => '127.0.0.1',
17+
'port' => 6379,
18+
'password' => '',
19+
'database' => 0,
20+
]);
21+
// REMOVE_START
22+
$r->flushall();
23+
// REMOVE_END
24+
25+
// STEP_START set_get
26+
$res1 = $r->set('bike:1', 'Deimos');
27+
echo "$res1" . PHP_EOL;
28+
// >>> OK
29+
30+
$res2 = $r->get('bike:1');
31+
echo "$res2" . PHP_EOL;
32+
// >>> Deimos
33+
// STEP_END
34+
// REMOVE_START
35+
$this->assertEquals('OK', $res1);
36+
$this->assertEquals('Deimos', $res2);
37+
// REMOVE_END
38+
39+
// STEP_START setnx_xx
40+
$res3 = $r->set('bike:1', 'bike', 'nx');
41+
echo "$res3" . PHP_EOL;
42+
// >>> (null)
43+
44+
echo $r->get('bike:1') . PHP_EOL;
45+
// >>> Deimos
46+
47+
$res4 = $r->set('bike:1', 'bike', 'xx');
48+
echo "$res4" . PHP_EOL;
49+
// >>> OK
50+
// STEP_END
51+
// REMOVE_START
52+
$this->assertEquals(null, $res3);
53+
$this->assertEquals('OK', $res4);
54+
$this->assertEquals('bike', $r->get('bike:1'));
55+
// REMOVE_END
56+
57+
// STEP_START mset
58+
$res5 = $r->mset([
59+
'bike:1' => 'Deimos', 'bike:2' => 'Ares', 'bike:3' => 'Vanth'
60+
]);
61+
echo "$res5" . PHP_EOL;
62+
// >>> OK
63+
64+
$res6 = $r->mget(['bike:1', 'bike:2', 'bike:3']);
65+
echo json_encode($res6) . PHP_EOL;
66+
// >>> ["Deimos","Ares","Vanth"]
67+
// STEP_END
68+
// REMOVE_START
69+
$this->assertEquals('OK', $res5);
70+
$this->assertEquals(['Deimos', 'Ares', 'Vanth'], $res6);
71+
// REMOVE_END
72+
73+
// STEP_START incr
74+
$r->set('total_crashes', 0);
75+
$res7 = $r->incr('total_crashes');
76+
echo "$res7" . PHP_EOL;
77+
// >>> 1
78+
79+
$res8 = $r->incrby('total_crashes', 10);
80+
echo "$res8" . PHP_EOL;
81+
// >>> 11
82+
// STEP_END
83+
// REMOVE_START
84+
$this->assertEquals(1, $res7);
85+
$this->assertEquals(11, $res8);
86+
// REMOVE_END
87+
}
88+
}

0 commit comments

Comments
 (0)