Skip to content

Execute Custom Commands

GLIDE’s custom_command method lets you execute any Valkey command directly, allowing you to execute custom commands, custom modules, and commands not yet supported by clients’ API.

Pass the command name and arguments as an array of strings:

import asyncio
from glide import GlideClient, GlideClientConfiguration, NodeAddress
async def main():
config = GlideClientConfiguration(
addresses=[NodeAddress("localhost", 6379)]
)
client = await GlideClient.create(config)
# Execute a SET command
await client.custom_command(["SET", "mykey", "hello"])
# Execute a GET command
result = await client.custom_command(["GET", "mykey"])
print(result) # b'hello'
if __name__ == "__main__":
asyncio.run(main())

Keep these constraints in mind when using custom commands:

  • Do not use for commands that alter connection state — e.g., SUBSCRIBE on RESP2.
  • Single-response commands only — Do not use for commands that return multiple responses (e.g., XREAD).
  • Key-based routing — In cluster mode, key-based commands are routed by the first key. Do not use multi-key commands that span different hash slots.