Key Operation Command

Source: Internet
Author: User
Tags set set

DEL key [key ...]Definition: Used to delete the existing key, the nonexistent key is ignored; Available version: >=1.0.0 return value: Number of keys deleted DUMP keyDefinition: Serializes the given key and returns the serialized value; Use the RESTORE command to deserialize the value into a Redis key (note: The serialized value does not contain any time-to-live information!) Available versions: >=2.6.0 return value: Returns the serialized value if key is present, otherwise returns nil RESTORE key ttl serialized-value [REPLACE]Definition: Deserializes the given serialized value and associates it with the given key;--The parameter TTL sets the time to live for key in milliseconds, or if the TTL is 0, it never expires (note: Restore performs a data checksum check on the RDB version of the serialized value before performing deserialization. If the RDB version is different or the data is incomplete, restore rejects the deserialization and returns an error) available version: >=2.6.0 return value: Deserialization successfully returns OK, otherwise returns an error message EXISTS key [key ...]Definition: Determine if the key is available version: >=1.0.0 return value: If key exists, returns 1; otherwise returns 0; EXPIRE key secondsDefinition: Setting key expiration time is seconds seconds, the key will be deleted automatically after expiration time, and the PERSIST command can be used to clear the timeout and make it a permanent key (note: All operations that change the value of a key conceptually will cause the expiration time to be cleared) available versions:> =1.0.0 return Value: Returns 1 if the setting is successful, or 0 if the key does not exist or fails to set PERSIST keyDefinition: Remove the time-to-live of a given key (turning a key with a time-to-live into a key that never expires) available version: >=2.2.0 return value: Remove successful return 1;key not present or key not set lifetime return 0 pexpire key millisecondsDefinition: Similar to expire, the difference is that the expire is in seconds, and Pexpire is the lifetime of the key set in milliseconds; Available versions: >=2.6.0 return value: Set successful return 1;key not present or set failure return 0 expireat key timestampDefinition: function similar to expire, used to set the lifetime of key (expiration time); The difference is that the accepted parameter timestamp is a UNIX timestamp available version: >=1.2.0 return value: Returns 1 if the setting is successful, or 0 if the key does not exist or fails to set pexpireat key Milliseconds-timestampDefinition: Similar to expireat, except that expireat is a Unix timestamp in seconds, and Pexpireat is a Unix timestamp in milliseconds to set the time to live; available version: >=2.6.0 return value: Set successful return 1 ; key does not exist or set failure return 0 KEYS pattrenDefinition: Finds all the regular expression patterns supported by keys that conform to the pattern of a given mode (regular expression):
    • H?llo match Hello,hallo,hxllo etc, i.e.? Match a single character
    • H*llo match Hllo,heeeello, i.e. * Match 0 or more characters
    • H[ae]llo matches only Hello and Hallo, that is, [XYZ] matches only the characters specified in the curly braces
    • H[^e]llo matches Hallo,hbllo, but does not match hello, that is, [^x] matches a single character other than X
    • H[a-b]llo matches Hallo and Hbllo, i.e. [x-y] matches only a single character within the range of X. to Y
Available version: >=1.0.0 return value: all eligible keys MIGRATE host Port key| "" Destination-db timeout [COPY] [REPLACE] [KEYS key [key ...]Definition: Transfers key atomicity from the current instance to the specified database of the target instance, and once the transfer succeeds, the key is guaranteed to appear on the target instance, and the key on the current instance is deleted (internally implemented: The current instance executes a dump command on the given key, serializes it, and then transfers it to the target instance. The target instance then deserializes the data using the Restore command and adds the deserialized data to the database, and the current instance receives the OK returned by the Restore command, and then calls Del to delete the corresponding key on its own database. The parameter description: timeout--in milliseconds format, Specifies the maximum interval of time that the current instance communicates with the target instance, that is, the time at which the data is transferred cannot exceed the timeout value copy--the keyreplace--of the current instance is overwritten on the target instance if the key parameter is an empty string, if the migration succeeds. The command uses the key following the keys parameter to migrate the available version: >=2.6.0 return value: "OK" is returned for successful migration and returns "Nokey" if no operational keys exist on the current instance MOVE key dbDefinition: Move the current database key to a given db (if the current database and target database have a key with the same name, or if the key does not exist in the current database, move has no effect, using this feature can use move as the lock primitive?? Available versions: >=1.0.0 return value: Move successfully returns 1; failure returns 0; OBJECT
    • OBJECT refcount = = This command is used for debugging, returning the number of times that the value of the specified key is referenced
    • OBJECT ENCODING = = This command returns the encoding used for the specified key corresponding to value (data compression mode)
    • OBJECT IDLETIME + = This command returns the value of the specified key corresponding to the time it was idle since it was stored (no request for read and write operations), in 10 seconds, which can be used to determine the eviction policy of the application tier key.
How to encode the object:
    1. String = raw (regular string) or int (a string representing a 64-bit unsigned integer, saving space)
    2. List type = Ziplist or LinkedList. Ziplist is a special coding method designed to save a smaller list space.
    3. set = = Intset or hashtable. Intset is a special coding method designed to store small sets of numbers
    4. Hash table = Zipmap or Hashtable. Zipmap is a special coding method designed for smaller collections
    5. Ordered set = = Ziplist or skiplist. Ziplist can represent smaller, ordered sets, and Skiplist represent an ordered set of arbitrary sizes
(Once an operation has been made for Redis to be unable to use the space-saving encoding, it will automatically convert those special encoding methods to normal encoding) available versions: >=2.2.3 return value: RefCount and IDLETIME subcommands return integers; ENCODING Returns an empty example if an attempt to check a parameter does not exist:redis> set Foo 1000okredis> object encoding foo "int" redis> append foo bar (integer) 7redis> get foo "1000bar" redis> object encoding foo "Raw" TTL keyDefinition: Returns the remaining lifetime of key; Available version: >=1.0.0 return value: Key's remaining lifetime (seconds) 1. Version <=2.6.0 returns 12 If key does not exist or key exists but has expired. Version >= 2.8.0, if key does not exist return-2 if key exists but has expired return-1 pttl keyDefinition: Similar to the TTL command, but it returns the remaining lifetime of key in milliseconds, and TTL in seconds; available version: >=2.6.0 return value: The remaining lifetime of key (in milliseconds) 1. Version <=2.6.0 returns 12 If key does not exist or key exists but has expired. Version >= 2.8.0, if key does not exist return-2 if key exists but has expired return-1 RandomkeyDefinition: Returns a random key from the current database available version: >=1.0.0 return value: Nil If the database does not have any key, otherwise a random key is returned RENAME key NewkeyDefinition: Rename key to Newkey, return an error message if key does not exist, overwrite the original if Newkey already exists, and return an error message if key is the same as Newkwy before 3.2.0 version: >=1.0.0 Renamenx key NewkeyDefinition: When and only if Newkey does not exist, it will be renamed to Newkey; If key does not exist, an error message is returned; available version: >=1.0.0 return value: Modify successfully returns 1 if Newkey already exists return 0; SCAN cursor [MATCH pattern] [count Count]Definition: Used to iterate a set element incrementally;
    • SCAN = To iterate over the key collection in the current database
    • Sscan = To iterate over the elements in the set set
    • HSCAN = used to iterate over key-value pairs in hash types
    • Zscan = The fractional value that corresponds to the elements and elements in the Iteration SortedSet collection
(The scan command does not need to provide any key in the first parameter because it iterates over all keys in the current database) available versions: >=2.8.0 SORT key [by pattern] [LIMIT offset count] [GET pattern] [ASC | DESC] [ALPHA] Destination TYPE keyDefinition: Returns the data structure type of value stored by key, and can return different types such as string/list/set/zset and hash; available version: >=1.0.0 return value: Returns the type of the current key, or none if key does not exist WAIT numslaves Timeout(If there is something wrong, welcome to make bricks!) )

Key Operation Command

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.