Wei-Yu Chen | ad55cb8 | 2022-02-15 20:07:01 +0800 | [diff] [blame^] | 1 | # SPDX-FileCopyrightText: 2020 The Magma Authors. |
| 2 | # SPDX-FileCopyrightText: 2022 Open Networking Foundation <support@opennetworking.org> |
| 3 | # |
| 4 | # SPDX-License-Identifier: BSD-3-Clause |
Wei-Yu Chen | 49950b9 | 2021-11-08 19:19:18 +0800 | [diff] [blame] | 5 | |
Wei-Yu Chen | 49950b9 | 2021-11-08 19:19:18 +0800 | [diff] [blame] | 6 | from redis.exceptions import RedisError |
| 7 | |
| 8 | # For non-failure cases, just use the fakeredis module |
| 9 | |
| 10 | |
| 11 | class MockUnavailableRedis(object): |
| 12 | """ |
| 13 | MockUnavailableRedis implements a mock Redis Server that always raises |
| 14 | a connection exception |
| 15 | """ |
| 16 | |
| 17 | def __init__(self, host, port): |
| 18 | self.host = host |
| 19 | self.port = port |
| 20 | |
| 21 | def lock(self, key): |
| 22 | raise RedisError("mock redis error") |
| 23 | |
| 24 | def keys(self, pattern=".*"): |
| 25 | """ Mock keys with regex pattern matching.""" |
| 26 | raise RedisError("mock redis error") |