disqus / gutter

Fully featured Python feature switch toolkit
Apache License 2.0
226 stars 29 forks source link

Persistence api is difficult to understand #18

Closed ghost closed 6 years ago

ghost commented 10 years ago

First of all, sorry for my ignorance, but I've tried to read the docs. I'm apparently missing something since I am the only one asking this.

Can someone give me an example configuration with persistence [of switches] with Redis?

Thank you.

NorthIsUp commented 10 years ago

There is an example from the docs here: https://github.com/disqus/gutter#configuring-settings

ghost commented 10 years ago
from gutter.client.settings import manager as manager_settings
from durabledict.redis import RedisDict
from redis import Redis as RedisClient
from gutter.client.models import Switch
from gutter.client.default import gutter

manager_settings.storage_engine = RedisDict('gutter', RedisClient())

switch = Switch('test')

gutter.register(switch)

Then

from gutter.client.settings import manager as manager_settings
from durabledict.redis import RedisDict
from redis import Redis as RedisClient
from gutter.client.models import Switch
from gutter.client.default import gutter

manager_settings.storage_engine = RedisDict('gutter', RedisClient())
gutter.switches
>>> []

This is what I mean with my problem with persistence... Any help is appreciated

NorthIsUp commented 10 years ago

Ah, simple and hard to find problem.

You need to set the storage_engine before you import the gutter client.

from gutter.client.settings import manager as manager_settings
from durabledict.redis import RedisDict
from redis import Redis as RedisClient
from gutter.client.models import Switch

manager_settings.storage_engine = RedisDict('gutter', RedisClient())

switch = Switch('test')

from gutter.client.default import gutter
gutter.register(switch)
from gutter.client.settings import manager as manager_settings
from durabledict.redis import RedisDict
from redis import Redis as RedisClient
from gutter.client.models import Switch

manager_settings.storage_engine = RedisDict('gutter', RedisClient())

from gutter.client.default import gutter
gutter.switches
NorthIsUp commented 10 years ago

@Fluxx We should change this api as it is super confusing.

from gutter.client import get_gutter

def get_gutter(name, options): return singleton.setdefault(name, Client(options))

options includes stuff to construct the connection

ghost commented 10 years ago

Hooray! Thank you

Fluxx commented 10 years ago

Yeah I actually ran into this problem yeaterday myself. I don't like the function approach as it only moves the problem around. I think we can probably just ditch the default manager or change the behavior of how it gets it's storage set to literally use the settings manager.

On Friday, July 25, 2014, Adam notifications@github.com wrote:

@Fluxx https://github.com/Fluxx We should change this api as it is super confusing.

from gutter.client import get_gutter

def get_gutter(name, options): return singleton.setdefault(name, Client(options))

options includes stuff to construct the connection

— Reply to this email directly or view it on GitHub https://github.com/disqus/gutter/issues/18#issuecomment-50145527.