# script tried accessing undeclared key

**URL:** <https://dragonfly.discourse.group/t/script-tried-accessing-undeclared-key/140>\
**Category:** Dragonfly Technical\
**Created:** [February 29, 2024, 4:14am UTC](https://dragonfly.discourse.group/t/script-tried-accessing-undeclared-key/140 "2024-02-29T04:14:38Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![unique-frog](https://avatars.discourse-cdn.com/v4/letter/u/e0b2c6/32.png) [@unique-frog](https://dragonfly.discourse.group/u/unique-frog)\
**Post date:** [February 29, 2024, 4:14am UTC](https://dragonfly.discourse.group/t/script-tried-accessing-undeclared-key/140/1 "2024-02-29T04:14:38Z")

</div>

hello. i want some help with my lua scritps

```lua
local cursor = '0'
local pattern = ARGV[1] .. ':*'

repeat
    local result = redis.call('SCAN', cursor, 'MATCH', pattern)
    cursor = result[1]
    local batchKeys = result[2]

    for _, key in ipairs(batchKeys) do
        redis.call('DEL', key)
    end
until cursor == '0'

return true

```

I get “script tried accessing undeclared key” when using `key` inside `for` clause. should i use `allow-undeclared-keys` flag in this case?

---

<div class="post-metadata">

**Author:** ![meaningful-vole](https://avatars.discourse-cdn.com/v4/letter/m/bb73d2/32.png) [@meaningful-vole](https://dragonfly.discourse.group/u/meaningful-vole)\
**Post date:** [March 4, 2024, 10:20am UTC](https://dragonfly.discourse.group/t/script-tried-accessing-undeclared-key/140/2 "2024-03-04T10:20:35Z")

</div>

Hi! Yes, this is the primary use case.  
You can add `disable-atomicity` if you don’t want to block the full keystore for this operation

---

<div class="post-metadata">

**Author:** ![unique-frog](https://avatars.discourse-cdn.com/v4/letter/u/e0b2c6/32.png) [@unique-frog](https://dragonfly.discourse.group/u/unique-frog)\
**Post date:** [March 4, 2024, 10:56am UTC](https://dragonfly.discourse.group/t/script-tried-accessing-undeclared-key/140/3 "2024-03-04T10:56:18Z")

</div>

thanks!

---

<div class="post-metadata">

**Author:** ![meaningful-vole](https://avatars.discourse-cdn.com/v4/letter/m/bb73d2/32.png) [@meaningful-vole](https://dragonfly.discourse.group/u/meaningful-vole)\
**Post date:** [March 4, 2024, 1:27pm UTC](https://dragonfly.discourse.group/t/script-tried-accessing-undeclared-key/140/4 "2024-03-04T13:27:21Z")

</div>

By the way, we also have an experimental feature 🙃 You can enable it with --lua\_auto\_async. If you run on multiple threads, it will parallelize the loop over batchkeys 😱
