Skip to content

Instantly share code, notes, and snippets.

@programmerShinobi
Last active October 25, 2024 12:15
Show Gist options
  • Save programmerShinobi/cd55a470dc6ad34b6a15230e6f404240 to your computer and use it in GitHub Desktop.
Save programmerShinobi/cd55a470dc6ad34b6a15230e6f404240 to your computer and use it in GitHub Desktop.
Redis Commander

Redis Commander

Here’s how you can use the KEYS command in Redis Commander:

Keys: KEYS

  • Command: KEYS pattern
  • Function: The KEYS command is used to find all keys matching a specific pattern. This can be especially helpful when you want to locate keys with a common prefix, suffix, or specific pattern in their names. In Redis Commander, you can use this command to search for keys that match the pattern you specify.
  • Example:
    • Pattern: example:*
    • Command: KEYS example:*
    • Output: A list of all keys matching the pattern, for example: ["example:string", "example:list", "example:set"].

Using KEYS in Redis Commander:

Redis Commander simplifies browsing and searching for keys:

  • You can directly use the search bar in Redis Commander to filter and display keys matching a specific pattern.
  • Redis Commander will show all matched keys in the sidebar, allowing you to explore each key and its type-specific functions without having to manually enter the KEYS command.

Using KEYS with patterns is a powerful way to locate keys by name convention, especially when managing a large set of data in Redis.


Redis Commander: Exploring Data Types and Commands

1. String: GET

  • Command: GET key
  • Function: This command is used to retrieve the value of a key of type string. In Redis Commander, when you select a key of type string, Redis Commander will display the value of the key directly on the dashboard.
  • Example**:
  • Key: example:string
  • Command: GET example:string
  • Output: “Hello, Redis!”

2. List: LINDEX

  • Command: LINDEX key index
  • Function: The LINDEX command is used to retrieve elements from a list at a specific position (by index). In Redis Commander, you can view list elements, and by selecting a key of type list, you can use this function to retrieve a specific element based on its index.
  • Example**:
  • Key: example:list
  • Command: LINDEX example:list 0
  • Output: The element at index 0 of the list.

3. Set: SMEMBERS

  • Command: SMEMBERS key
  • Function: SMEMBERS is used to retrieve all members of a set. Redis Commander will display all elements of a key of type set automatically after you select the key in the dashboard.
  • Example**:
  • Key: example:set
  • Command: SMEMBERS example:set
  • Output: All members of the set, for example [“apple”, “banana”, “orange”].

4. Hash: HGETALL

  • Command: HGETALL key
  • Function: HGETALL is used to retrieve all fields and values from a key of type hash. In Redis Commander, when you select a key of hash type, all the associated fields and values will be displayed automatically using this command.
  • Example:
  • Key: example:hash
  • Command: HGETALL example:hash
  • Output: {“field1”: “value1”, ‘field2’: “value2"}

Functions in Redis Commander:

In Redis Commander, these components work automatically according to the key type:

  • When you select a key of type string, Redis Commander will use GET to display the string value.
  • When you select a key of type list, Redis Commander will display a list, and you can select elements by index using LINDEX.
  • For set, Redis Commander will display all members of the set with the SMEMBERS command.
  • For hash, Redis Commander will utilize HGETALL to display all field and value pairs.

Redis Commander makes it easy to explore data without manually typing commands, as it recognizes key types and automatically displays relevant results based on those Redis commands. commands, as it recognizes key types and automatically displays relevant results based on those Redis commands.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment