import inspect
import redis
import yaaredis
def test_function():
aredis = set(dir(yaaredis.Redis))
red = set(dir(redis.Redis))
# print(dir(aredis))
# print('------')
# print(dir(red))
print("currently, yaaredis lack those methods")
print(red - aredis) # todo checkthis
both = red & aredis
print("\nbesides, those methods hava different signature, during this test, aredis's method can have more params")
for func in both:
try:
redis_ins = inspect.signature(getattr(redis.Redis, func))
aredis_ins = inspect.signature(getattr(yaaredis.Redis, func))
for name, param in redis_ins.parameters.items():
if name not in aredis_ins.parameters:
print(f"aredis.Redis.{func} not equal to redis-py, expect {redis_ins} got {aredis_ins}")
break
# if str(redis_ins) != str(aredis_ins):
# print(f"{func} not equal,redis-py is{redis_ins} but aredis is {aredis_ins}")
except TypeError:
print(f"{func} is not callable, ignore")
except ValueError:
print(f"{func} is builtin, ignore")
print('\ncheck response callbacks\n')
# check response callbacks
for cb, fn in redis.Redis.RESPONSE_CALLBACKS.items():
if cb not in yaaredis.Redis.RESPONSE_CALLBACKS:
print(f'aredis lack callback for {cb} command, whose function name is {fn}')
else:
try:
if fn.__code__.co_code != yaaredis.Redis.RESPONSE_CALLBACKS[cb].__code__.co_code:
print(f"aredis's callback {cb} is different from redis-py's, expect {fn}, got {yaaredis.Redis.RESPONSE_CALLBACKS[cb]}, copy that from redis-py should be ok", flush=True)
except AttributeError: # class type
if fn != yaaredis.Redis.RESPONSE_CALLBACKS[cb]:
print(f"aredis's callback {cb} is different from redis-py's, expect {fn}, got {yaaredis.Redis.RESPONSE_CALLBACKS[cb]}, copy that from redis-py should be ok", flush=True)
test_function()
using this test script to find out any difference