Upstash Documentation

FCALL_RO

Call a read-only function.
2 min read

Use FCALL_RO to invoke a function that is declared read-only.

The function must have been registered with the no-writes flag; calling a function without it returns an error. In exchange the server knows the call cannot modify data, so it can serve it on replicas and reject accidental writes outright.

Apart from that restriction it behaves like FCALL: <numkeys> splits the arguments into the keys the function receives in KEYS and the plain arguments it receives in ARGV.

Being read-only does not by itself make the call concurrent with others. The function takes the global lock unless it was also registered with the allow-key-locking flag, as in flags={'no-writes', 'allow-key-locking'}. With both flags, the call takes shared read locks on the keys passed in the key list, so several readers of the same key proceed together. See Key-Based Locking.

Syntax#

Arguments#

ArgumentRequiredRepeatableDescription
<function>YesNoName of the registered function to call.
<numkeys>YesNoNumber of key arguments that follow.
<key>NoYesRedis key targeted by the command.
<arg>NoYesAdditional argument passed to the function.

Important points#

  • numkeys must equal the number of key arguments that immediately follow it; remaining arguments are available to the script or function as ordinary arguments.
  • A no-writes function still takes the global lock unless it was also registered with the allow-key-locking flag. See Key-Based Locking.
  • Pass every key the function reads in the key list whether or not allow-key-locking is set. A key built inside the function is read from disk under the lock when it is not in memory, and it is rejected outright when the flag is set. See Dynamic Keys and Latency.

Response#

The reply reports the result of the operation. Error replies have the same shape in RESP2 and RESP3 and are surfaced as exceptions by the SDKs below.

ProtocolReply
RESP2Reply returned by the invoked read-only function
RESP3Reply returned by the invoked read-only function
Note

Client libraries often decode bulk strings, maps, sets, and numeric strings into language-native values. The table describes the Redis wire reply.

Examples#

TCP examples use the TLS REDIS_URL from the Upstash console. REST examples use UPSTASH_REDIS_REST_URL and UPSTASH_REDIS_REST_TOKEN.

Redis CLI
@upstash/redis
upstash_redis
Note

This command is not supported yet in upstash_redis.

ioredis
node-redis
redis-py
go-redis
jedis
redis-rs