Skip to content

Commit 3390efb

Browse files
committed
Apply code review suggestions
1 parent b16f021 commit 3390efb

File tree

2 files changed

+35
-16
lines changed

2 files changed

+35
-16
lines changed

local_examples/cmds_hash/NRedisStack/CmdsHashExample.cs

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,14 @@ public void Run()
2323

2424
RedisValue hdelRes3 = db.HashDelete("myhash", "field1");
2525
Console.WriteLine(hdelRes3); // >>> 0
26-
2726
// STEP_END
27+
28+
// REMOVE_START
2829
Assert.True(hdelRes1);
2930
Assert.Equal(1, hdelRes2);
3031
Assert.Equal(0, hdelRes3);
3132
db.KeyDelete("myhash");
33+
// REMOVE_END
3234

3335
// STEP_START hget
3436
bool hgetRes1 = db.HashSet("myhash", "field1", "foo");
@@ -38,12 +40,14 @@ public void Run()
3840

3941
RedisValue hgetRes3 = db.HashGet("myhash", "field2");
4042
Console.WriteLine(hgetRes3); // >>> Null
41-
4243
// STEP_END
44+
45+
// REMOVE_START
4346
Assert.True(hgetRes1);
4447
Assert.Equal("foo", hgetRes2);
4548
Assert.Equal(RedisValue.Null, hgetRes3);
4649
db.KeyDelete("myhash");
50+
// REMOVE_END
4751

4852
// STEP_START hset
4953
bool hsetRes1 = db.HashSet("myhash", "field1", "Hello");
@@ -67,8 +71,9 @@ public void Run()
6771
HashEntry[] hsetRes5 = db.HashGetAll("myhash");
6872
Console.WriteLine($"{string.Join(", ", hsetRes5.Select(h => $"{h.Name}: {h.Value}"))}");
6973
// >>> field1: Hello, field2: Hi, field3: World
70-
7174
// STEP_END
75+
76+
// REMOVE_START
7277
Assert.True(hsetRes1);
7378
Assert.Equal("Hello", hsetRes2);
7479
Assert.Equal("Hi", hsetRes3);
@@ -78,6 +83,7 @@ public void Run()
7883
string.Join(", ", hsetRes5.Select(h => $"{h.Name}: {h.Value}"))
7984
);
8085
db.KeyDelete("myhash");
86+
// REMOVE_END
8187

8288
// STEP_START hgetall
8389
db.HashSet("myhash",
@@ -94,8 +100,11 @@ public void Run()
94100
);
95101
// >>> field1: Hello, field2: World
96102
// STEP_END
103+
104+
// REMOVE_START
97105
Assert.Equal("field1: Hello, field2: World", string.Join(", ", hGetAllResult.Select(e => $"{e.Name}: {e.Value}")));
98106
db.KeyDelete("myhash");
107+
// REMOVE_END
99108

100109
// STEP_START hvals
101110
db.HashSet("myhash",
@@ -110,8 +119,11 @@ public void Run()
110119
Console.WriteLine(string.Join(", ", hValsResult));
111120
// >>> Hello, World
112121
// STEP_END
122+
123+
// REMOVE_START
113124
Assert.Equal("Hello, World", string.Join(", ", hValsResult));
114125
db.KeyDelete("myhash");
126+
// REMOVE_END
115127

116128
// STEP_START hexpire
117129
// Set up hash with fields
@@ -139,12 +151,14 @@ public void Run()
139151
// >>> -2
140152
// STEP_END
141153

154+
// REMOVE_START
142155
RedisValue[] expireResult1 = (RedisValue[])hexpireRes1;
143156
RedisValue[] expireResult3 = (RedisValue[])hexpireRes3;
144157
Assert.Equal("1, 1", string.Join(", ", expireResult1));
145158
Assert.Equal(2, ttlValues.Length);
146159
Assert.True(ttlValues.All(ttl => (int)ttl > 0)); // TTL should be positive
147160
Assert.Equal("-2", string.Join(", ", expireResult3));
148161
db.KeyDelete("myhash");
162+
// REMOVE_END
149163
}
150164
}

local_examples/cmds_hash/predis/CmdsHashTest.php

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,7 @@ protected function setUp(): void
2626

2727
public function testCmdsHash(): void
2828
{
29-
echo "\n=== Testing Redis Hash Commands ===\n";
30-
3129
// STEP_START hdel
32-
echo "\n--- HDEL Command ---\n";
3330
$hDelResult1 = $this->redis->hset('myhash', 'field1', 'foo');
3431
echo "HSET myhash field1 foo: " . $hDelResult1 . "\n"; // >>> 1
3532

@@ -40,12 +37,13 @@ public function testCmdsHash(): void
4037
echo "HDEL myhash field2: " . $hDelResult3 . "\n"; // >>> 0
4138
// STEP_END
4239

40+
// REMOVE_START
4341
$this->assertEquals(1, $hDelResult1);
4442
$this->assertEquals(1, $hDelResult2);
4543
$this->assertEquals(0, $hDelResult3);
44+
// REMOVE_END
4645

4746
// STEP_START hget
48-
echo "\n--- HGET Command ---\n";
4947
$hGetResult1 = $this->redis->hset('myhash', 'field1', 'foo');
5048
echo "HSET myhash field1 foo: " . $hGetResult1 . "\n"; // >>> 1
5149

@@ -56,26 +54,29 @@ public function testCmdsHash(): void
5654
echo "HGET myhash field2: " . ($hGetResult3 ?? 'null') . "\n"; // >>> null
5755
// STEP_END
5856

57+
// REMOVE_START
5958
$this->assertEquals(1, $hGetResult1);
6059
$this->assertEquals('foo', $hGetResult2);
6160
$this->assertNull($hGetResult3);
61+
// REMOVE_END
6262

6363
// STEP_START hgetall
64-
echo "\n--- HGETALL Command ---\n";
6564
$hGetAllResult1 = $this->redis->hmset('myhash', ['field1' => 'Hello', 'field2' => 'World']);
6665
echo "HMSET myhash field1 Hello field2 World: " . ($hGetAllResult1 ? 'OK' : 'FAIL') . "\n"; // >>> OK
6766

6867
$hGetAllResult2 = $this->redis->hgetall('myhash');
6968
echo "HGETALL myhash: " . json_encode($hGetAllResult2) . "\n"; // >>> {"field1":"Hello","field2":"World"}
7069
// STEP_END
7170

71+
// REMOVE_START
7272
$this->assertEquals('OK', $hGetAllResult1);
7373
$this->assertEquals(['field1' => 'Hello', 'field2' => 'World'], $hGetAllResult2);
74+
// REMOVE_END
7475

7576
// STEP_START hset
76-
echo "\n--- HSET Command ---\n";
77-
// Clean up first
77+
// REMOVE_START
7878
$this->redis->del('myhash');
79+
// REMOVE_END
7980

8081
$hSetResult1 = $this->redis->hset('myhash', 'field1', 'Hello');
8182
echo "HSET myhash field1 Hello: " . $hSetResult1 . "\n"; // >>> 1
@@ -100,17 +101,19 @@ public function testCmdsHash(): void
100101
echo "\n";
101102
// STEP_END
102103

104+
// REMOVE_START
103105
$this->assertEquals(1, $hSetResult1);
104106
$this->assertEquals('Hello', $hSetResult2);
105107
$this->assertEquals('OK', $hSetResult3);
106108
$this->assertEquals('Hi', $hSetResult4);
107109
$this->assertEquals('World', $hSetResult5);
108110
$this->assertEquals(['field1' => 'Hello', 'field2' => 'Hi', 'field3' => 'World'], $hSetResult6);
111+
// REMOVE_END
109112

110113
// STEP_START hvals
111-
echo "\n--- HVALS Command ---\n";
112-
// Clean up first
114+
// REMOVE_START
113115
$this->redis->del('myhash');
116+
// REMOVE_END
114117

115118
$hValsResult1 = $this->redis->hmset('myhash', ['field1' => 'Hello', 'field2' => 'World']);
116119
echo "HMSET myhash field1 Hello field2 World: " . ($hValsResult1 ? 'OK' : 'FAIL') . "\n"; // >>> OK
@@ -119,13 +122,15 @@ public function testCmdsHash(): void
119122
echo "HVALS myhash: " . json_encode($hValsResult2) . "\n"; // >>> ["Hello","World"]
120123
// STEP_END
121124

125+
// REMOVE_START
122126
$this->assertEquals('OK', $hValsResult1);
123127
$this->assertEquals(['Hello', 'World'], $hValsResult2);
128+
// REMOVE_END
124129

125130
// STEP_START hexpire
126-
echo "\n--- HEXPIRE Command ---\n";
127-
// Clean up first
131+
// REMOVE_START
128132
$this->redis->del('myhash');
133+
// REMOVE_END
129134

130135
// Set up hash with fields
131136
$hExpireResult1 = $this->redis->hmset('myhash', ['field1' => 'Hello', 'field2' => 'World']);
@@ -144,13 +149,13 @@ public function testCmdsHash(): void
144149
echo "HEXPIRE myhash 10 FIELDS nonexistent: " . json_encode($hExpireResult4) . "\n"; // >>> [-2]
145150
// STEP_END
146151

152+
// REMOVE_START
147153
$this->assertEquals('OK', $hExpireResult1);
148154
$this->assertEquals([1, 1], $hExpireResult2);
149155
$this->assertEquals(2, count($hExpireResult3));
150156
$this->assertTrue(array_reduce($hExpireResult3, function($carry, $ttl) { return $carry && $ttl > 0; }, true)); // TTL should be positive
151157
$this->assertEquals([-2], $hExpireResult4);
152-
153-
echo "\n=== All Hash Commands Tests Passed! ===\n";
158+
// REMOVE_END
154159
}
155160

156161
protected function tearDown(): void

0 commit comments

Comments
 (0)