blob: 0978932455e8c633099a4503507ef2e22e24d7cb [file] [log] [blame]
Wei-Yu Chen49950b92021-11-08 19:19:18 +08001"""
2Copyright 2020 The Magma Authors.
3
4This source code is licensed under the BSD-style license found in the
5LICENSE file in the root directory of this source tree.
6
7Unless required by applicable law or agreed to in writing, software
8distributed under the License is distributed on an "AS IS" BASIS,
9WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10See the License for the specific language governing permissions and
11limitations under the License.
12"""
13from redis.exceptions import RedisError
14
15# For non-failure cases, just use the fakeredis module
16
17
18class MockUnavailableRedis(object):
19 """
20 MockUnavailableRedis implements a mock Redis Server that always raises
21 a connection exception
22 """
23
24 def __init__(self, host, port):
25 self.host = host
26 self.port = port
27
28 def lock(self, key):
29 raise RedisError("mock redis error")
30
31 def keys(self, pattern=".*"):
32 """ Mock keys with regex pattern matching."""
33 raise RedisError("mock redis error")