@@ -78,4 +78,72 @@ public function itShouldNotClearWholeRedisOnFlush(): void
78
78
])
79
79
);
80
80
}
81
+
82
+ /**
83
+ * @test
84
+ */
85
+ public function itShouldOnlyConnectOnceOnSubsequentCalls (): void
86
+ {
87
+ $ clientId = $ this ->redisConnection ->rawCommand ('client ' , 'id ' );
88
+ $ expectedClientId = 'id= ' . ($ clientId + 1 ) . ' ' ;
89
+ $ notExpectedClientId = 'id= ' . ($ clientId + 2 ) . ' ' ;
90
+
91
+ $ redis = new Redis (['host ' => REDIS_HOST ]);
92
+
93
+ $ redis ->collect ();
94
+
95
+ $ this ->assertStringContainsString (
96
+ $ expectedClientId ,
97
+ $ this ->redisConnection ->rawCommand ('client ' , 'list ' )
98
+ );
99
+ $ this ->assertStringNotContainsString (
100
+ $ notExpectedClientId ,
101
+ $ this ->redisConnection ->rawCommand ('client ' , 'list ' )
102
+ );
103
+
104
+ $ redis ->collect ();
105
+
106
+ $ this ->assertStringContainsString (
107
+ $ expectedClientId ,
108
+ $ this ->redisConnection ->rawCommand ('client ' , 'list ' )
109
+ );
110
+ $ this ->assertStringNotContainsString (
111
+ $ notExpectedClientId ,
112
+ $ this ->redisConnection ->rawCommand ('client ' , 'list ' )
113
+ );
114
+ }
115
+
116
+ /**
117
+ * @test
118
+ */
119
+ public function itShouldOnlyConnectOnceForInjectedRedisConnectionOnSubsequentCalls (): void
120
+ {
121
+ $ clientId = $ this ->redisConnection ->rawCommand ('client ' , 'id ' );
122
+ $ expectedClientId = 'id= ' . $ clientId . ' ' ;
123
+ $ notExpectedClientId = 'id= ' . ($ clientId + 1 ) . ' ' ;
124
+
125
+ $ redis = Redis::fromExistingConnection ($ this ->redisConnection );
126
+
127
+ $ redis ->collect ();
128
+
129
+ $ this ->assertStringContainsString (
130
+ $ expectedClientId ,
131
+ $ this ->redisConnection ->rawCommand ('client ' , 'list ' )
132
+ );
133
+ $ this ->assertStringNotContainsString (
134
+ $ notExpectedClientId ,
135
+ $ this ->redisConnection ->rawCommand ('client ' , 'list ' )
136
+ );
137
+
138
+ $ redis ->collect ();
139
+
140
+ $ this ->assertStringContainsString (
141
+ $ expectedClientId ,
142
+ $ this ->redisConnection ->rawCommand ('client ' , 'list ' )
143
+ );
144
+ $ this ->assertStringNotContainsString (
145
+ $ notExpectedClientId ,
146
+ $ this ->redisConnection ->rawCommand ('client ' , 'list ' )
147
+ );
148
+ }
81
149
}
0 commit comments