How are Buffers converted to string internally?

オープン
#1,553 コメント 1 件 リアクション 1 件 担当者 0 名 GitHub で見る

メンテナーはふだん 1 日以内に返信

まだ誰も着手していません。

評価

難易度
3/5
見積もり時間
1〜2日
初心者へのやさしさ
25/100
issue の種類
ドキュメント
明瞭さ
説明が足りない
活発さ
停滞
技術スタック
node.js, redis
領域
backend, database

調査の方向性

参照されている index.js の stream-write コードと、リンクされている node-redis-test の例から始め、次にクライアントが Buffer と Buffer.toString() をどのように処理するかを追跡します。観測された Redis の値を、記載されている Node.js および Redis のバージョンと比較します。変換の動作と、保存された 2 つの値が異なる理由を文書化できれば完了です。

索引モデルが issue の本文から書いたものです。

説明

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

主要言語
TypeScript
スター
17.6k
フォーク
2k
平均マージ
1日 22時間
マージ済み PR(30日)
62

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

redis/node-redis のほかの issue

redis/node-redis の issue をすべて見る

似ている issue

TypeScript の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。