How are Buffers converted to string internally?

Abierto
#1,553 1 comentario 1 reacción 0 asignados Ver en GitHub

Los mantenedores suelen responder en 1 día

Nadie ha tomado este issue todavía.

Evaluación

Dificultad
3/5
Tiempo estimado
1-2 días
Aptitud para principiantes
25/100
Tipo de issue
Documentación
Claridad
Necesita aclaración
Estado de actividad
Estancado
Stack tecnológico
node.js, redis
Área
backend, database

Línea de trabajo

Comienza con el código stream-write referenciado de index.js y el ejemplo enlazado de node-redis-test; después, sigue cómo el cliente gestiona un Buffer frente a Buffer.toString(). Compara los valores de Redis observados con las versiones de Node.js y Redis indicadas. Se considerará terminado cuando se documente el comportamiento de conversión y por qué difieren los dos valores almacenados.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

I apologize in advance for asking the question here - I've originally posted my question on stackoverflow, but after 10 days I still didn't manage to get the answer that I was looking for... I thought I might try my luck here 😄. If it's not ok to ask the question here, let me know and I'll remove it...

I'm not having any issues with the library, but I'm trying to figure out how Buffer is being handled in node-redis library. I have my nodejs script that fetches some data from database, serializes and gzips the result and then stores that result in redis. Later I read this value in php script, so I need to match what php script expects

In node gzip library returns Buffer and what I'm wondering is how does node-redis convert this Buffer to string internally?

When I pass Buffer (from gzip) to redis, it will be saved in the format that my php script can read and decode properly

await client.setex('compressed', 3600, compressed);

Value in redis (result is from redis desktop manager terminal)

redis1:0>get "compressed'
"\x1F\x8B\x08\x00\x00\x00\x00\x00\x02\x03\xABVJI,IT\xB2R*I-.Q\xAA\x05\x00\xC0\xE3/\xAC\x0F\x00\x00\x00"

But when I pass Buffer.toString() to redis, php won't be able to read and decode

await client.setex('compressed', 3600, compressed.toString());

Value in redis

redis1:0>get "compressed-toString"
"\x1F\xEF\xBF\xBD\x08\x00\x00\x00\x00\x00\x02\x03\xEF\xBF\xBDVJI,IT\xEF\xBF\xBDR*I-.Q\xEF\xBF\xBD\x05\x00\xEF\xBF\xBD\xEF\xBF\xBD/\xEF\xBF\xBD\x0F\x00\x00\x00"

Now I'm trying to figure out how exactly is node-redis converting this buffer to string internally? Why are these 2 values different? Best that I could find is this stream write, but I'm still not clear on how exactly it works and why are the redis values different...

Any help is appreciated!


Test example

I've created simple example


Environment
  • Node.js Version: v12.18.3

  • Redis Version: 5.0.5 (redis:5.0.5-alpine)

  • Platform: Ubuntu 20.04

Lenguaje dominante
TypeScript
Estrellas
17.6k
Forks
2k
Merge medio
1 d 22 h
PR fusionados (30 d)
62

Preparar el entorno

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de redis/node-redis

Todos los issues de redis/node-redis

Issues similares

Más issues de TypeScript

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.