• 周六. 10 月 12th, 2024

5G编程聚合网

5G时代下一个聚合的编程学习网

热门标签

Redis learning distributed lock (1) the difference between setnx, set, setex, GetSet

King Wang

1 月 3, 2022

One .redis Knowledge about

1.SET key value

meaning :

          String value value Related to key .

          If key Has held other values , SET Just overwrite the old value , Ignore the type .

example :

 

2.SETEX key seconds value

meaning :

            Will value value Related to key , And will key The lifetime of is set to seconds ( In seconds ).

            If key Already exist , SETEX The command will override the old value .

Return value :

            When the setting is successful, return OK .

            When seconds When the parameter is illegal , Return an error .

 

 

3.SETNX key value

meaning :

            take key The value of the set value , If and only if key non-existent .

            If a given key Already exist , be SETNX Don’t do anything .

           SETNX yes 『SET if Not eXists』( If it doesn’t exist , be SET) Abbreviation .

Return value :

            Set up the success , return 1 .

            Setup failed , return 0 .

example :

 

4.GETSET key value

meaning :

          Will be given key The value of the set value , And back to key The old value (old value).

          When key When it exists but is not a string type , Return an error .

Return value :

            Return to a given key The old value .

            When key When there is no old value , That is to say , key When there is no , return nil .

发表回复