Python: serialize ice proxy to save into redis database
I have an Ice Application implemented in Python and I use icestorm to connect different endpoints.
Currently, I keep the proxy of endpoints in app memory and when any endpoints wants to connect with another, I simply create the topic in icestorm.
Now, I want to save the proxies in a redis as part of one class instance but I can't do it using json.dumps or pickle.dumps since the proxy is not a standard type.
- JSON library: throws a TypeError (object is not json serializable) when I try to dumps the object in a JSON.
- pickle library: save action its ok but throws a RuntimeError ('A proxy cannot be created directly) when I try to loads from redis.
Is there any way to serialize and deserialize the proxy in redis using python? I don't care if I have to create a string or json manually, serializing and deserializing the proxy manually in some way.
You can use
ice_toStringto convert the proxy to a string and then
communicator.stringToProxy(...)to convert it back the string to a proxy, you might also need uncheckedCast to get the correct proxy type.
serialized = prx.ice_toString() prx = FooPrx.uncheckedCast(communicator.stringToProxy(serialized))1
The solution provided is valid.