As you may know, Redis is basically a data-structure store that uses key-value pairs to store the data and supports strings, integers, sets, lists, hashes, and so on. To access the data faster, we can implement Redis.
Once you are connected to the command-line (CLI) of the Redis, you are able to use some commands to work with the keys. In this article, I want to share these commands with a brief explanation for you.
This command will connect you to the database of {database_number} in Redis.
This command shows all available keys in Redis (note that: when the TTL of a key finishes, the key is automatically destroyed).
Use this command with the key's name. It shows the type of the key. For example, if the type of the key is hash, the command returns a hash.
If the key is a list of values, you can use this command to get the value of each index. You may know that in lists, the index starts from "0" to "length of the list-1". For example, lindex {key_name} 1, will return the value of index 1 in list {key_name}.
This command deletes the given keys with {key_name1} {key_name2} and so on.
If the key is hash and you want to get all fields and the related values in the key, you can use this command. For example, if a key is hash and has two fields "a" and "b" with values of ‘x’ and ‘y’ respectively; if you use this command, you will get "a", x, "b", and y in response.
If the type of the key is hash and you want to get the value of a specific field in the key, you can use this command. For example, imagine a key is hash and has two fields "a" and "b". The value of field “a” is ‘x’.
To get x, you can use: hget {key_name} a
This command returns the value that the key holds. It works when the type of the key is not hash or list.
This command deletes all keys in Redis.
This command returns the TTL of the key in seconds.
This command creates a key named {key_name} with a value in Redis. This command works when you want to create a key that is not a list or hash.