I'm using redis to stores a bitfield data and I set a u4 value in on each offset.
I need to get the buffer in Nodejs server.
for 0-7,redis returns the correct buffer.
But when setting 8-15 value.It returns a strange buffer.Uint8Array views into the buffer and it shows [239,191,189] which represents messy code. here is the copy-to-run test code.
btw problem ocurrs with the resoponse buffer.Trying to get the #0 value is ok.
const http = require('http');
const url = require('url');
const fs = require('fs');
const redis = require('redis'),
RDS_PORT = 6379,
RDS_HOST = '139.199.33.69',//139.199.33.69
RDS_OPTS = {detect_buffers: true},
client = redis.createClient(RDS_PORT, RDS_HOST, RDS_OPTS);
console.log('redis ready')
const canvas_name = 'canvas-bitfield';
client.del(canvas_name)
client.send_command("bitfield",[canvas_name,'SET','u4','#0',10,'OVERFLOW','FAIL'])
client.send_command('bitfield',[canvas_name,'GET','u4',0],redis.print) //reply:10
client.get(canvas_name,function(err, reply){
if(err){console.log(err)}
const buff = Buffer.from(reply.toString());
const view8 = new Uint8Array(buff);
console.log(view8) //Uint8Array(3) [239, 191, 189]
})
via Natsu
No comments:
Post a Comment