[Python] Redis value is java float array, is it possible to store the same float array value...

Discussão em 'Python' iniciado por Stack, Setembro 2, 2025.

  1. Stack

    Stack Membro Participativo

    In a java program, data is saved into database in text type like"[0.1, 0.2]", and the program also save a copy into redis in java float[] form, like this:

    ReactiveHashOperations<String, String, float[]> matrixOps = ...;
    matrixOps.put(k1, k2, floatArray))


    Then I realize in redis some records are missing, I prefer using python to do the same. However, I don't know if python could store the same java float[] into redis?

    Now in python, I am using a py4j to read text "[0.1, 0.2]" out and call java function in ConvertTextToFloatArray.class. and save that java function returned float array into redis. I don't know if this could work.

    Add: I found that a 256 length Java float array, stored in redis, after read out in python, it occupies 1051 bytes.

    r = redis.Redis(**redis_config)
    binary_data = r.hget(redis_key, sub_key)
    print(f"{len(binary_data)}")

    Continue reading...

Compartilhe esta Página