-
Notifications
You must be signed in to change notification settings - Fork 107
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
base: master
Are you sure you want to change the base?
Changes from 3 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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,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) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sorry was just looking at the documentation and ran a quick test observed that `
So basically you don't need to convert them into int. |
||
except ValueError: | ||
result[name] = value | ||
return result | ||
|
||
# PubSub commands # | ||
|
||
def publish(self, channel, message): | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
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') | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you also add a test for ints? |
||
eq_(self.redis.config_get('config-param'), {'config-param': 'value'}) | ||
eq_(self.redis.config_get('config*'), {'config-param': 'value'}) | ||
|
||
def test_config_set_int_value(self): | ||
eq_(self.redis.config_get('config-param-int'), {}) | ||
self.redis.config_set('config-param-int', 123) | ||
eq_(self.redis.config_get('config-param-int'), | ||
{'config-param-int': 123}) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You should be returning "OK". For more info, http://redis.io/commands/config-set
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, we get
redis.exceptions.ResponseError: Unsupported CONFIG parameter: a
for an invalid config. We probably need a list of configs to mimic the ResponseError. Not required for this PR though.