Skip to main content

cmd_expiretime.go

cmd_expiretime.go - Overview

This file defines the EXPIRETIME command, which retrieves the expiration time of a given key in a DiceDB store. It includes the command's metadata, evaluation, and execution logic.

Detailed Documentation

CommandMeta: cExpireTime

  • Purpose: Defines the metadata for the EXPIRETIME command, including its name, syntax, help text, examples, and associated functions for evaluation and execution.
  • Fields:
    • Name: The name of the command ("EXPIRETIME").
    • Syntax: The command's syntax ("EXPIRETIME key").
    • HelpShort: A short description of the command.
    • HelpLong: A detailed description of the command's functionality.
    • Examples: Example usages of the command.
    • Eval: The function to evaluate the command (evalEXPIRETIME).
    • Execute: The function to execute the command (executeEXPIRETIME).

Function: init

  • Purpose: Registers the EXPIRETIME command with the CommandRegistry.

Function: evalEXPIRETIME

  • Purpose: Evaluates the EXPIRETIME command against a given data store. It retrieves the key's expiration time and returns it as a Unix timestamp.
  • Parameters:
    • c: A pointer to the Cmd struct representing the command.
    • dst: A pointer to the dstore.Store struct representing the data store.
  • Returns:
    • *CmdRes: A pointer to the CmdRes struct representing the command result. The result contains the expiration Unix timestamp in seconds, -1 if the key exists but has no expiration time, or -2 if the key does not exist.
    • error: An error object, which is nil if the command executed successfully.

Function: executeEXPIRETIME

  • Purpose: Executes the EXPIRETIME command within a sharded environment. It retrieves the appropriate shard based on the key, then evaluates the command against that shard's store.
  • Parameters:
    • c: A pointer to the Cmd struct representing the command.
    • sm: A pointer to the shardmanager.ShardManager struct.
  • Returns:
    • *CmdRes: A pointer to the CmdRes struct representing the command result.
    • error: An error object, which is non-nil if there are an incorrect number of arguments.

Getting Started Relevance