diff --git a/mockredis/client.py b/mockredis/client.py index 998d3c5..fd5e927 100644 --- a/mockredis/client.py +++ b/mockredis/client.py @@ -8,6 +8,7 @@ import re import sys import time +import fnmatch from mockredis.clock import SystemClock from mockredis.lock import MockRedisLock @@ -51,6 +52,7 @@ def __init__(self, self.blocking_sleep_interval = blocking_sleep_interval # The 'Redis' store self.redis = defaultdict(dict) + self.redis_config = defaultdict(dict) self.timeouts = defaultdict(dict) # The 'PubSub' store self.pubsub = defaultdict(list) @@ -1354,6 +1356,25 @@ def _normalize_command_response(self, command, response): return response + # Config Set/Get commands # + + def config_set(self, name, value): + """ + Set a configuration parameter. + """ + self.redis_config[name] = str(value) + return True + + def config_get(self, pattern='*'): + """ + Get one or more configuration parameters. + """ + result = {} + for name, value in self.redis_config.items(): + if fnmatch.fnmatch(name, pattern): + result[name] = value + return result + # PubSub commands # def publish(self, channel, message): diff --git a/mockredis/tests/test_config.py b/mockredis/tests/test_config.py new file mode 100644 index 0000000..0b06836 --- /dev/null +++ b/mockredis/tests/test_config.py @@ -0,0 +1,27 @@ +from nose.tools import eq_, ok_ + +from mockredis.tests.fixtures import setup, teardown + + +class TestRedisConfig(object): + """Redis config set/get tests""" + + def setup(self): + setup(self) + + def teardown(self): + teardown(self) + + def test_config_set(self): + ok_(self.redis.config_set('loglevel', 'debug')) + eq_(self.redis.config_get('loglevel'), {'loglevel': 'debug'}) + ok_(self.redis.config_set('loglevel', 'notice')) + eq_(self.redis.config_get('loglevel'), {'loglevel': 'notice'}) + eq_(self.redis.config_get('loglev*'), {'loglevel': 'notice'}) + + def test_config_set_int_value(self): + ok_(self.redis.config_set('hz', 12)) + eq_(self.redis.config_get('hz'), {'hz': '12'}) + ok_(self.redis.config_set('hz', 10)) + eq_(self.redis.config_get('hz'), {'hz': '10'}) +