Files
2012-02-21 01:15:00 -05:00

1 line
7.1 KiB
JSON

[{"user_id": 1579, "stars": [], "topic_id": 6212, "date_created": 1297808601.553539, "message": "I'm probably missing something basic but is there a way to get unicode strings directly from redis.py?", "group_id": 292, "id": 116050}, {"user_id": 2588, "stars": [], "topic_id": 6212, "date_created": 1297826562.462163, "message": "I don't think so. The Redis client is just returning byte strings it reads back from the socket.", "group_id": 292, "id": 117492}, {"user_id": 2588, "stars": [], "topic_id": 6212, "date_created": 1297826857.623486, "message": "AFAICT your best bet is to subclass BaseConnection, using the read_response from PythonConnection but modifying it to decode to your preferred encoding when the respone type is a byte (string). Then you'll create a ConnectionPool with your connection class and pass the ConnectionPool to the Redis constructor.", "group_id": 292, "id": 117498}, {"user_id": 1579, "stars": [], "topic_id": 6212, "date_created": 1297848752.977469, "message": "I did find in hiredis-py a reference to decode bulk data to any python supported encoding. Since redis.py actually uses hiredis if it can be imported I'll have a go at defining it in HiredisConnection first as it seems a bit simpler (to my knowledge level)", "group_id": 292, "id": 118538}, {"user_id": 1579, "stars": [], "topic_id": 6212, "date_created": 1297848271.8345349, "message": "@unbracketed Thanks for the pointers! I'm rather new to python (and redis :)", "group_id": 292, "id": 118524}, {"user_id": 723, "stars": [], "topic_id": 6212, "date_created": 1297849784.4625199, "message": "The safest all-purpose solution I could find was to force the type-casting/character decoding to the application, because that's what knows what kind of data should be coming back from a given key.", "group_id": 292, "id": 118614}, {"user_id": 1579, "stars": [], "topic_id": 6212, "date_created": 1297850361.0104649, "message": "Hi @andy, thanks! I understand redis.py's design choices, I was wondering which way to go if/when it's something one needs. I have been using the strategy you mention but what do you think about using hiredis.Reader's encoding argument? I'm using this with virtualenv(s) so I could have a separate instance running like that...", "group_id": 292, "id": 118672}, {"user_id": 723, "stars": [], "topic_id": 6212, "date_created": 1297849685.2353489, "message": "The reason redis-py *doesn't* automatically decode to is that it has no idea what kind of data you're storing.", "group_id": 292, "id": 118600}, {"user_id": 723, "stars": [], "topic_id": 6212, "date_created": 1297849700.9408901, "message": "For example, many people use Redis to store serialized JSON structures.", "group_id": 292, "id": 118601}, {"user_id": 1579, "stars": [], "topic_id": 6212, "date_created": 1297850449.4087639, "message": "/needs/fancies/", "group_id": 292, "id": 118680}, {"user_id": 1579, "stars": [], "topic_id": 6212, "date_created": 1297876608.655493, "message": "any further comment would be greatly appreciated", "group_id": 292, "id": 121564}, {"user_id": 723, "stars": [], "topic_id": 6212, "date_created": 1297878088.3048811, "message": "Or two different client instances?", "group_id": 292, "id": 121774}, {"user_id": 1579, "stars": [], "topic_id": 6212, "date_created": 1297876502.0899141, "message": "ok, so I made the option a parameter to redis.Redis(). It's also reflected on ConnectionPool.make_connection_key() so I can have both types of connections concurrently. So now, every dataset I need to pass to (e.g.) jinja2 can come directly from a hgetall command on a automatic decoded redis connection while any other type of data can use the standard redis connection and deal with types per case.", "group_id": 292, "id": 121550}, {"user_id": 1579, "stars": [], "topic_id": 6212, "date_created": 1297878411.0656791, "message": "I'm using two different client instances", "group_id": 292, "id": 121818}, {"user_id": 723, "stars": [], "topic_id": 6212, "date_created": 1297877984.622442, "message": "@pnbv On initial thought, that seems reasonable.", "group_id": 292, "id": 121766}, {"user_id": 723, "stars": [], "topic_id": 6212, "date_created": 1297878082.2613759, "message": "Are you using the same client instance for both, and swapping connections somehow underneath?", "group_id": 292, "id": 121773}, {"user_id": 1579, "stars": [], "topic_id": 6212, "date_created": 1297879056.4463191, "message": "Thanks for the pointers! I will definitely be looking into this more closely, thanks again!", "group_id": 292, "id": 121908}, {"user_id": 723, "stars": [], "topic_id": 6212, "date_created": 1297879150.8469629, "message": "Sure. The parse_response idea might fall over with pipelines.", "group_id": 292, "id": 121921}, {"user_id": 723, "stars": [], "topic_id": 6212, "date_created": 1297878433.226934, "message": "Ya that makes sense.", "group_id": 292, "id": 121823}, {"user_id": 723, "stars": [], "topic_id": 6212, "date_created": 1297878522.3476081, "message": "Perhaps an easier way", "group_id": 292, "id": 121835}, {"user_id": 723, "stars": [], "topic_id": 6212, "date_created": 1297878536.089113, "message": "would be to subclass redis.Client and override parse_response", "group_id": 292, "id": 121838}, {"user_id": 723, "stars": [], "topic_id": 6212, "date_created": 1297878575.997468, "message": "You could call super(), then do something like, if isinstance(response, basestring): response = unicode(response)", "group_id": 292, "id": 121844}, {"user_id": 723, "stars": [], "topic_id": 6212, "date_created": 1297878596.8465371, "message": "or appropriate character decoding, etc.", "group_id": 292, "id": 121846}, {"user_id": 723, "stars": [], "topic_id": 6212, "date_created": 1297880221.011194, "message": "We can split apart parse_response", "group_id": 292, "id": 122256}, {"user_id": 723, "stars": [], "topic_id": 6212, "date_created": 1297880207.0539629, "message": "It's actually pretty easy to fix though.", "group_id": 292, "id": 122249}, {"user_id": 1579, "stars": [], "topic_id": 6212, "date_created": 1297880116.8650441, "message": "ok", "group_id": 292, "id": 122212}, {"user_id": 1579, "stars": [], "topic_id": 6212, "date_created": 1297900462.222497, "message": "ok, parse_response is already dealing with lists for multiline responses so I guess that if one has to iterate over it to apply the unicode function one might as well just do this at the application level.", "group_id": 292, "id": 126731}, {"user_id": 1579, "stars": [], "topic_id": 6212, "date_created": 1297901604.5026901, "message": "I'm not sure that the same applies when one goes deeper into read_response and the read function from BaseConnection and PythonConnection as advised by @unbracketed since I'm not familiar with python to understand all of it yet.", "group_id": 292, "id": 127027}, {"user_id": 1579, "stars": [], "topic_id": 6212, "date_created": 1297901669.3236229, "message": "The nice thing about using HiredisConnection is that it already expects an encoding argument to the reader function of the Hiredis client, so, with this small option it is really easy to turn on or off unicode string output (per client instance) . I haven't tested it for all redis commands but for the most part it seems non problematic.", "group_id": 292, "id": 127055}]