pallets-eco / flask-session

Server side session extension for Flask
https://flask-session.readthedocs.io
BSD 3-Clause "New" or "Revised" License
501 stars 239 forks source link

Add support for decode_responses=True to RedisSessionInterface? #72

Closed decentral1se closed 7 years ago

decentral1se commented 7 years ago

I am using fakeredis as my Redis connection in my unit tests and it offers a decode_responses argument which avoid returning bytes:

>>> from fakeredis import FakeRedis
>>> rds_without, rds_with = FakeRedis(), FakeRedis(decode_responses=True))
>>> rds_without['a'] = 1
>>> rds_with['a'] = 1
>>> rds_without['a'], rds_with['a']
(b'1', '1')
>>> rds_with.keys()
['session:068678b2-4ecd-4747-91f4-624826d85447', 'a']
>>> rds_without.keys()
[b'session:068678b2-4ecd-4747-91f4-624826d85447', b'a']

As far as I can see in my tests your RedisSessionInterface doesn't support this argument and everything comes back as bytes? In fact, I can't do lookups without bytes:

>>> session
<RedisSession {'_permanent': True, b'foo': b'bar'}>
>>> session['foo']
*** KeyError: 'foo'
decentral1se commented 7 years ago

Hmmmm, things just magically started working. I think it's my hangover but I can't be sure.