Skip to main content
Glama
redis

Redis MCP Server

Official
by redis

hset

Set or update a field in a Redis hash with an optional expiration time. Specify the hash key, field name, value, and optional expiry in seconds for efficient data management.

Instructions

Set a field in a hash stored at key with an optional expiration time.

Args: name: The Redis hash key. key: The field name inside the hash. value: The value to set. expire_seconds: Optional; time in seconds after which the key should expire.

Returns: A success message or an error message.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
expire_secondsNo
keyYes
nameYes
valueYes

Implementation Reference

  • The main handler function for the 'hset' MCP tool. It sets a field in a Redis hash with optional expiration, decorated with @mcp.tool() for automatic registration.
    @mcp.tool() async def hset( name: str, key: str, value: str | int | float, expire_seconds: Optional[int] = None ) -> str: """Set a field in a hash stored at key with an optional expiration time. Args: name: The Redis hash key. key: The field name inside the hash. value: The value to set. expire_seconds: Optional; time in seconds after which the key should expire. Returns: A success message or an error message. """ try: r = RedisConnectionManager.get_connection() r.hset(name, key, str(value)) if expire_seconds is not None: r.expire(name, expire_seconds) return f"Field '{key}' set successfully in hash '{name}'." + ( f" Expires in {expire_seconds} seconds." if expire_seconds else "" ) except RedisError as e: return f"Error setting field '{key}' in hash '{name}': {str(e)}"
  • The @mcp.tool() decorator registers the hset function as an MCP tool.
    @mcp.tool()

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/redis/mcp-redis'

If you have feedback or need assistance with the MCP directory API, please join our Discord server