PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Monday, September 5, 2022

[FIXED] What are Redis options object key titles for KEEPTTL & XX (update if present)?

 September 05, 2022     javascript, redis     No comments   

Issue

I have updated my Redis verison to "^4.2.0" in Node and I have to convert my old client.set methods to use the options object instead of comma separated options.

I have been able to do this with setting a value because the documentation says the key titles for expiring is "EX" like...

const setValue = async (key, value, exp) => {
   await client.set(key, JSON.stringify(value), { EX: exp }) 
}

But what are the options object key titles for "KEEPTTL" & "XX" (update if present)??? See question marks below...

const updateValue = async (key, value) => {
   await client.set(key, JSON.stringify(value), { <?>: "KEEPTTL", <?>: "XX" })
}


Solution

XX means only set the key, if the key already exists, i.e. do not add a new key.

KEEPTTL is a new option Redis 6.0. By default, when you call set key value on a key, the expiration time (TTL) will be reset, i.e. no TTL any more. However, with this option, you can only change the value, without modifying the TTL.



Answered By - for_stack
Answer Checked By - Cary Denson (PHPFixing Admin)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing