Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add basic config_set / config_get support. #84

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions mockredis/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import re
import sys
import time
import fnmatch

from mockredis.clock import SystemClock
from mockredis.lock import MockRedisLock
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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):
Expand Down
27 changes: 27 additions & 0 deletions mockredis/tests/test_config.py
Original file line number Diff line number Diff line change
@@ -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'})