
The index -1 as the start will translate to the last element which has 4 index(if list include 4 elements) SO the condition start > end has been applyed Next Command Will Remove all elements under list IF list include more than one elements BUT IF list include only one element will Not Remove any thing LTRIM list -1 0įirst Case (list include more than one elements) Start and end can also be negative numbers indicating offsets from theĮnd of the list, where -1 is the last element of the list, -2 the SO any of next Commands will works or Mohd Abdul Mujib's solution LTRIM list 999 0īut Take care about using negative numbers as The start index, as From Documentation Result will be an empty list (which causes key to be removed).

If start is larger than the end of the list, or start > end, the Using LTRIM Command and Applying The next conditional from Documentation Using General DEL Command for delete any key into Redis like Anurag's solution DEL list Since KEYS is returning potentially every key in the system, this can have a dramatic negative impact on performance.There Different ways to Remove all element from the List :

Here we want all keys that contain the text 'title': > KEYS *title*ĬAUTION: As mentioned in the official documentation, it is advisable to avoid using the KEYS command on very large databases, but in particular avoid using it in a production environment. The syntax following KEYS can be used to search for specific words or phrases within the key, or the exact match as well. Thus, we not only see our two original title and author keys but also the four enumerated versions that followed as well. To get a list of all current keys that exist, simply use the KEYS command: > KEYS *īy following KEYS with an asterisk ( *) – which acts as a wildcard search – we’re asking Redis to retrieve all keys in the system. Now using GET requires adding the unique numeric key as well: > GET title:1Īs it turns out, every SET command we issued above created a new, unique key within our Redis database. Instead, we can use namespace syntax by using a : separator and giving each title or author entry a unique numeric key: > SET title:1 "The Hobbit" That’s all well and good, but how do we add another book? We can’t reuse the same title and author keys or we’ll overwrite the existing data. So we can view them with GET, like so: > GET title

The title and author are the keys we’ve set and the actual string values were specified after. This is best shown through the redis-cli (command line interface) using GET and SET commands.įor example, we may want to store some information about books, such as the title and author of a few of our favorites. Most (But Not All) Objects Use a Keyįor the vast majority of data storage with Redis, data will be stored in a simple key/value pair. During development in particular, it can be tricky to keep track of everything that exists in the database already, so in this brief tutorial we’ll cover the method for retrieving all keys from a Redis database with some simple commands.

Since Redis is non-relational, everything in the system is configured with basic key/value pairs at the simplest level. This is particularly true when Redis is compared to a more traditional relational databases with quarantined tables, each containing multiple rows and columns to house data. Like other non-relational database engines, wrapping your mind around how Redis handles data structures and associations can sometimes be difficult.
