def test_redisrpc_obj(redisdb): """Objects are not JSON serializable by default.""" server = start_thread(redisdb) client = redisrpc.Client(redisdb, Foo.MESSAGE_QUEUE, timeout=TIMEOUT, transport='pickle') assert client.return_obj() == Bar()
def test_redisrpc_dict(redisdb): server = start_thread(redisdb) client = redisrpc.Client(redisdb, Foo.MESSAGE_QUEUE, timeout=TIMEOUT) assert client.return_dict() == dict(a=1, b=2)
def test_redisrpc_list(redisdb): server = start_thread(redisdb) client = redisrpc.Client(redisdb, Foo.MESSAGE_QUEUE, timeout=TIMEOUT) assert client.return_list() == [1, 2, 3]
def test_redisrpc_string(redisdb): server = start_thread(redisdb) client = redisrpc.Client(redisdb, Foo.MESSAGE_QUEUE, timeout=TIMEOUT) assert client.return_string() == "STRING"
def test_redisrpc_float(redisdb): server = start_thread(redisdb) client = redisrpc.Client(redisdb, Foo.MESSAGE_QUEUE, timeout=TIMEOUT) assert abs(client.return_float() - 3.14159) < 1e-15
def test_redisrpc_false(redisdb): server = start_thread(redisdb) client = redisrpc.Client(redisdb, Foo.MESSAGE_QUEUE, timeout=TIMEOUT) assert client.return_false() is False
args = parser.parse_args() def do_calculations(calculator): calculator.clr() calculator.add(5) calculator.sub(3) calculator.mul(4) calculator.div(2) assert calculator.val() == 4 try: calculator.missing_method() assert False except (AttributeError, redisrpc.RemoteException): pass # 1. Local object calculator = calc.Calculator() do_calculations(calculator) # 2. Remote object, should act like local object redis_server = redis.Redis() message_queue = 'calc' calculator = redisrpc.Client(redis_server, message_queue, timeout=1, transport=args.transport) do_calculations(calculator) print('success!')
import calc # Direct all RedisPRC logging messages to stderr. logging.basicConfig(stream=sys.stderr, level=logging.DEBUG) def do_calculations(calculator): calculator.clr() calculator.add(5) calculator.sub(3) calculator.mul(4) calculator.div(2) assert calculator.val() == 4 try: calculator.missing_method() assert False except (AttributeError, redisrpc.RemoteException): pass # 1. Local object calculator = calc.Calculator() do_calculations(calculator) # 2. Remote object, should act like local object redis_server = redis.Redis() message_queue = 'calc' calculator = redisrpc.Client(redis_server, message_queue, timeout=1) do_calculations(calculator) print('success!')