【发布时间】:2023-03-02 22:21:01
【问题描述】:
我在redis中做setbit操作,标记某天有哪些用户在线。
我正在做一个redis get操作来获取key的值。
coffee> redis.setbit "a",7,1
true
coffee> redis.setbit "d",4,1
true
coffee> redis.setbit "g",1,1
true
coffee> redis.setbit "h",0,1
输出是
coffee> redis.get "a",(err,res)->console.log res.toString().charCodeAt(0)
true
coffee> 1
coffee> redis.get "d",(err,res)->console.log res.toString().charCodeAt(0)
true
coffee> 8
coffee> redis.get "g",(err,res)->console.log res.toString().charCodeAt(0)
true
coffee> 64
coffee> redis.get "h",(err,res)->console.log res.toString().charCodeAt(0)
true
coffee> 65533
我的问题是我将第 0 位设置为 1 的“h”键。它应该返回 128 但返回 65533。为什么会这样?
我的最终目标是从 redis 中获取二进制位图,以便我可以了解在特定日期哪些用户处于活动状态。
【问题讨论】:
-
你是在解析 unicode 字符吗?
-
不,它是redis中的位图,所以它可以是任何随机字符串,具体取决于哪些位将设置为1
-
通过 redis-cli 测试时,
GET h返回“\x80”(或十进制的 128)。 -
是的,我也检查过了,我得到一个 80 的缓冲区对象,但是当转换为字符串时,它返回 65533。有什么想法吗?
-
听起来客户端模块和/或堆栈设置有问题。仍然怀疑字符集 gremlin。
标签: node.js coffeescript redis