# EVAL_RO

> Run a read-only Lua script.

URL: https://docs.hotkv.com/commands/eval_ro/

```
EVAL_RO script numkeys [key [key ...]] [arg [arg ...]]
```

- Group: Scripting and functions
- Complexity: Depends on the script
- HotKV Cloud: all plans
- On-Premise: no license needed

`EVAL_RO` runs a Lua script like [EVAL](https://docs.hotkv.com/commands/eval/index.md), but the script may
not write. Because the command itself is read-only, you can send it to
read-only replicas and grant it to users who are not allowed to write. Any
write command the script tries fails with
`ERR Write commands are not allowed from read-only scripts.`

A script with a shebang line must declare the `no-writes` flag to run with
`EVAL_RO`; otherwise it is refused before it starts.

## Return value

The script's return value, converted as described for
[EVAL](https://docs.hotkv.com/commands/eval/index.md).

Errors, in addition to those of `EVAL`:

- `ERR Can not execute a script with write flag using *_ro command.` for a
  script with a shebang line that lacks `no-writes`.
- `ERR Write commands are not allowed from read-only scripts.` when the script
  tries to write.

## Examples

```
127.0.0.1:6379> SET greeting "hello"
OK
127.0.0.1:6379> EVAL_RO "return redis.call('GET', KEYS[1])" 1 greeting
"hello"
127.0.0.1:6379> EVAL_RO "#!lua flags=no-writes
return redis.call('STRLEN', KEYS[1])" 1 greeting
(integer) 5
```

## Compatibility

Same as Redis 7 and Valkey 8.

## See also

[EVAL](https://docs.hotkv.com/commands/eval/index.md), [EVALSHA_RO](https://docs.hotkv.com/commands/evalsha_ro/index.md),
[FCALL_RO](https://docs.hotkv.com/commands/fcall_ro/index.md)