DEL
The DEL command is used to delete one or more specified keys. Non-existent keys are ignored. The time complexity of the DEL command is O(N), where N is the number of keys to be deleted. When the key to be deleted holds a value other than a string, the individual complexity of that key is O(M), where M is the number of elements in the list, set, sorted set, or hash. The time complexity of deleting a single key holding a string value is O(1).
Redis Native Command Syntax
Section titled “Redis Native Command Syntax”DEL key [key ...]Parameter Description
- key: The key(s) to delete, multiple keys can be specified
Detailed Explanation
Section titled “Detailed Explanation”The DEL command is used to delete the specified keys and their associated values from the Redis database. If the specified keys do not exist, the DEL command ignores these keys without generating an error.
The DEL command is applicable to keys of different data types, including strings, lists, sets, sorted sets, and hashes.
Redisun Usage
Section titled “Redisun Usage”In redisun, the DEL command is implemented through the DelCommand class and the del method in the Redisun class.
Basic Usage
Section titled “Basic Usage”Redisun redisun = Redisun.create(options -> { options.setHost("localhost"); options.setPort(6379);});
// Delete a single keyint deletedCount = redisun.del("mykey");
// Delete multiple keys (array form)int deletedCount = redisun.del("key1", "key2", "key3");
// Delete multiple keys (list form)List<String> keys = Arrays.asList("key1", "key2", "key3");int deletedCount = redisun.del(keys);- The DEL command immediately deletes the specified keys and releases related memory
- Non-existent keys are ignored and not counted in the deletion count
- The DEL command is applicable to keys of all data types
- For large data structures, the DEL command may block the server for a period of time