The basic syntax of the redis set command is as follows:
redis 127.0.0.1:6379> SET KEY_NAME VALUE
Before redis 2.6.12, the set command always returned OK.
From redis2.6.12, set returns OK when the setting operation is completed successfully
Create a key in redis and set the value.
#Set keys that do not exist redis 127.0.0.1:6379> SET key "value" OK redis 127.0.0.1:6379> GET key "value" #Set the existing key redis 127.0.0.1:6379> SET key "new-value" OK redis 127.0.0.1:6379> GET key "new-value"
Redis key command is used to manage redis keys.
The basic syntax of redis key command is as follows:
redis 127.0.0.1:6379> COMMAND KEY_NAME
redis 127.0.0.1:6379> SET runoobkey redis OK redis 127.0.0.1:6379> DEL runoobkey(integer) 1
In the above example, del is a command and runoobkey is a key. If the key is deleted successfully, output (integer) 1 after command execution, otherwise output (integer) 0
Basic commands related to redis key:
This command is used to delete the key when it exists.
2 、DUMP key
Serializes the given key and returns the serialized value.
Check whether the given key exists.
4、EXPIRE key seconds
Sets the expiration time in seconds for the given key.
5、EXPIREAT key timestamp
The function of expire is similar to that of expire, which is used to set the expiration time for the key. The difference is that the time parameter accepted by the expire command is UNIX timestamp.
6 、PEXPIRE key milliseconds
Set the expiration time of the key in milliseconds.
7、PEXPIREAT key milliseconds-timestamp
Set the UNIX timestamp of the key expiration time in milliseconds
Find all keys that match the given pattern.
9、MOVE key db
Move the key of the current database to the given database db.
Remove the expiration time of the key, and the key will be persisted.
Returns the remaining expiration time of the key in milliseconds.
Returns the TTL (time to live) of a given key in seconds.
Returns a key randomly from the current database.
14、RENAME key newkey
Modify the name of key
15、RENAMENX key newkey
Only if the newkey does not exist, change the name of the key to newkey.
Returns the type of value the key stores.