Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ERR syntax error when using set #1269

Closed
dotSlashLu opened this issue Aug 24, 2017 · 5 comments
Closed

ERR syntax error when using set #1269

dotSlashLu opened this issue Aug 24, 2017 · 5 comments
Labels

Comments

@dotSlashLu
Copy link

  • Version:
    node_redis: ^2.8.0
    redis-server: Redis server v=4.0.1 sha=00000000:0 malloc=libc bits=64 build=f37081b32886670b

  • Platform:
    Node.js v8.3.0
    Darwin 16.7.0 Darwin Kernel Version 16.7.0: Thu Jun 15 17:36:27 PDT 2017; root:xnu-3789.70.16~2/RELEASE_X86_64 x86_64

  • Description:
    set will result in 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)

will generate

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
@BridgeAR
Copy link
Contributor

Please check the readme. You have to add 'EX' or 'PX' depending on what type of timeout you want.

@dotSlashLu
Copy link
Author

Thanks

@atuttle
Copy link

atuttle commented Mar 30, 2020

In case anyone else lands on this issue from a search and is not particularly helped by what's here, here's what helped me. I was trying to do a set with an inline TTL: redis.set(key, value, ttl, callback), and was getting a similar syntax error.

It seems that you can't do the TTL inline like that. Instead, do your set without the TTL argument, and then if you really need to set a TTL for that key, follow that request with a call to redis.ttl().

@stockholmux
Copy link
Contributor

@atuttle That's not quite right. Node_redis just relays the commands to Redis. What you're wanting to do is this for inline setting of the TTL client.set(key, value,'EX', ttl, callback), as per the SET command's documentation.

Additionally, the client.ttl() command gets the time to live not sets it. If you want to do it set the TTL you have to use client.expire().

@atuttle
Copy link

atuttle commented Apr 1, 2020

Thanks for the correction.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants