Skip to content

Commit

Permalink
Merge pull request #106 from RedisLabs/config-support
Browse files Browse the repository at this point in the history
Add basic config_set / config_get support.
  • Loading branch information
srikalyan authored Jun 27, 2016
2 parents 517897e + 5e4fb95 commit 8155ed0
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 0 deletions.
22 changes: 22 additions & 0 deletions mockredis/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,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)
Expand Down Expand Up @@ -1396,6 +1397,27 @@ 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] = value

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):
try:
result[name] = int(value)
except ValueError:
result[name] = value
return result

# PubSub commands #

def publish(self, channel, message):
Expand Down
20 changes: 20 additions & 0 deletions mockredis/tests/test_config.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
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):
eq_(self.redis.config_get('config-param'), {})
self.redis.config_set('config-param', 'value')
eq_(self.redis.config_get('config-param'), {'config-param': 'value'})
eq_(self.redis.config_get('config*'), {'config-param': 'value'})

0 comments on commit 8155ed0

Please sign in to comment.