File: scripting.rst

package info (click to toggle)
redis-py-cluster 2.0.0-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 748 kB
  • sloc: python: 5,888; ruby: 1,045; makefile: 542
file content (27 lines) | stat: -rw-r--r-- 1,073 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# Scripting support

Scripting support is limited to scripts that operate on keys in the same key slot.
If a script is executed via `evalsha`, `eval` or by calling the callable returned by
`register_script` and the keys passed as arguments do not map to the same key slot,
a `RedisClusterException` will be thrown.

It is however, possible to query a key within the script, that is not passed
as an argument of `eval`, `evalsha`. In this scenarios it is not possible to detect
the error early and redis itself will raise an error which will be percolated
to the user. For example:

```python
    cluster = RedisCluster('localhost', 7000)
    script = """
    return redis.call('GET', KEYS[1]) * redis.call('GET', ARGV[1])
    """
    # this will succeed
    cluster.eval(script, 1, "A{Foo}", "A{Foo}")
    # this will fail as "A{Foo}" and "A{Bar}" are on different key slots.
    cluster.eval(script, 1, "A{Foo}", "A{Bar}")
```

## Unsupported operations

- The `SCRIPT KILL` command is not yet implemented.
- Scripting in the context of a pipeline is not yet implemented.