Node-redis: 使用set时出现“ ERR语法错误”

创建于 2017-08-24  ·  5评论  ·  资料来源: NodeRedis/node-redis

  • 版本号
    node_redis:^ 2.8.0
    redis服务器:Redis服务器v = 4.0.1 sha = 00000000:0 malloc = libc位= 64 build = f37081b32886670b

  • 平台
    Node.js v8.3.0
    Darwin 16.7.0 Darwin Kernel版本16.7.0:PDT 2017年6月15日17:36:27; 根目录:xnu-3789.70.16〜2 / RELEASE_X86_64 x86_64

  • 说明
    set将产生ERR syntax error

const redis = require('redis'),
      Promise = require('bluebird'),
      conf = require(__root_dir + '/conf/conf')

// Promise.promisifyAll(redis.RedisClient.prototype)
// Promise.promisifyAll(redis.Multi.prototype)
const client = redis.createClient(
    conf.redis.port,
    conf.redis.host)

const key = 'sess-test'
const uid = 1
const ttl = 60 * 60 * 24 * 30
client.set(key, uid, ttl)

会产生

Send localhost:6379 id 0: *4
$3
set
$9
sess-test
$1
1
$7
2592000

Net read localhost:6379 id 0
Error ReplyError: ERR syntax error
question

最有用的评论

请检查自述文件。 您必须根据所需的超时类型添加“ EX”或“ PX”。

所有5条评论

请检查自述文件。 您必须根据所需的超时类型添加“ EX”或“ PX”。

谢谢

如果有人通过搜索找到了这个问题,而这里的内容并没有为您带来特别的帮助,那么这就是对我有帮助的地方。 我试图使用内联TTL进行设置: redis.set(key, value, ttl, callback) ,并且遇到了类似的语法错误。

看来您无法像这样进行TTL内联。 相反,请在不使用TTL参数的情况下进行设置,然后,如果您确实需要为该键设置TTL,请在该请求后调用redis.ttl()

@atuttle不太正确。 Node_redis只是将命令中继到Redis。 根据SET命令的文档,您要针对TTL client.set(key, value,'EX', ttl, callback)内联设置执行此操作。

此外, client.ttl()命令_获取生存时间不会设置它。 如果要设置TTL,则必须使用client.expire()

感谢您的更正。

此页面是否有帮助?
0 / 5 - 0 等级

相关问题

strumwolf picture strumwolf  ·  4评论

adamgajzlerowicz picture adamgajzlerowicz  ·  4评论

twappworld picture twappworld  ·  7评论

lemon707 picture lemon707  ·  3评论

Stono picture Stono  ·  6评论