def test_memoryviews_are_not_packed(self): c = Connection() arg = memoryview(b"some_arg") arg_list = ["SOME_COMMAND", arg] cmd = c.pack_command(*arg_list) assert cmd[1] is arg cmds = c.pack_commands([arg_list, arg_list]) assert cmds[1] is arg assert cmds[3] is arg
def handle(self, *args, **options): owner_username = args[0] audience_name = args[1] filename = os.path.abspath(args[2]) redis_key = Profiles.ip_audiences_key # the connection is not necessary, but the object is used to # format redis commands to redis protocol using pack_command redis_connection = Connection(host=settings.profiles_redis_host, port=settings.profiles_redis_port) user = User.objects.get(username=owner_username) audience, _ = Audience.objects.get_or_create(name=audience_name, owner=user.account, is_ip=True) audience_id = audience.public_id with open(filename) as csvfile: reader = csv.reader(csvfile) for row in reader: ip = IPAddress(row[0]).packed sys.stdout.write( redis_connection.pack_command("SADD", redis_key.format(ip), audience_id))