Strings
Using KEYS will block the server when scanning for all the data. This might lead to latency in large databases and can affect other users. It is not to be used in Production.
SETNX: Sets the value of a key only if the key does not exist.
SETNX "character:rachel" "Fashion"
SETEX: Sets the value of a key with an expiration time.
SETEX "character:rachel" 60 "Fashion"
(expires in 60 seconds)MSET: Sets multiple keys to multiple values in a single atomic operation.
MSET "character:rachel" "Fashion" "character:ross" "Paleontologist"
MGET: Gets the values of all the given keys.
MGET "character:rachel" "character:ross"
INCR: Increments the integer value of a key by one.
INCR "pageviews:rachelProfile" GET "pageviews:rachelProfile"
DECR: Decrements the integer value of a key by one.
DECR "stock:centralPerkMugs"
INCRBY: Increments the integer value of a key by the given amount.
INCRBY "followers:rachel" 10
DECRBY: Decrements the integer value of a key by the given number.
DECRBY "debt:rachel" 100
INCRBYFLOAT: Increments the float value of a key by the given amount.
INCRBYFLOAT "balance:rachel" 100.50
GETSET: Sets a new value and returns the old value.
GETSET "character:rachel" "Executive"
MSETNX: Sets multiple keys to multiple values only if none exist.
MSETNX "character:rachel" "Fashion" "character:monica" "Chef"
PSETEX: Similar to
SETEX
PSETEX but with an expiration time in milliseconds.PSETEX "character:rachel" 60000 "Fashion"
(expires in 60,000 milliseconds or 60 seconds)
Last updated