Want to perform cross slot operations

151 views
Skip to first unread message

Sabyasachi Sahoo

unread,
Jun 8, 2023, 9:00:34 AM6/8/23
to Redis DB
Hello,
I want to perform some cross slot operations.
When I explored, I found that a flag(allow-cross-slot-keys) was added in this PR - https://github.com/redis/redis-doc/pull/1893/files
I tried to apply this flag in script as well as function but no luck.
I am trying to do this via java app. 
redis version - 7.0.11
client library - lettuce.

I'm stuck for quite sometime now
Please help, thanks in advance.

Thanks and Regards,
Sabya

Sotto Voce

unread,
Jun 8, 2023, 11:50:55 PM6/8/23
to Redis DB
You mention "script" and "function", but it's not clear whether you're talking about LUA scripts/functions invoked by the EVAL/FCALL commands, or you're talking about ordinary key read and write commands.  Are you working with LUA scripts or functions?

Sabyasachi Sahoo

unread,
Jun 9, 2023, 1:12:57 AM6/9/23
to Redis DB
Hello Sotto,
I am talking about Lua Script and Functions

#!lua flags=allow_cross_slot_keys
local function add_user(keys, user_code, parent_code)
    local exists = redis.call('EXISTS', parent_code)

    if exists == 1 then
        redis.call('SADD', parent_code .. ':children', user_code)
        redis.call('INCR', parent_code .. ':version')
        redis.call('SET', user_code, parent_code)
        redis.call('SET', user_code .. ':version', '1')
    end

    return true
end

redis.register_function{
    function_name = 'add_user',
    callback = add_user,
    flags = { 'allow-cross-slot-keys' }
}

here parent_code and user_code are in different slots.

Regards,
Sabya

Madelyn Olson

unread,
Jun 10, 2023, 12:41:01 PM6/10/23
to Redis DB
Using scripts that cross slots is considered an anti-pattern in Redis. The flag you mentioned is mostly intended for compatibility with older scripts which might have been previously accessing cross slots, see https://redis.io/docs/manual/programmability/lua-api/#script_flags. You should investigate if you can modify  your script to use hash tags to follow best practices.

-Madelyn
--
You received this message because you are subscribed to the Google Groups "Redis DB" group.
To unsubscribe from this group and stop receiving emails from it, send an email to redis-db+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/redis-db/dc61a882-7a21-4ab9-978b-8638bda1d531n%40googlegroups.com.

Sabyasachi Sahoo

unread,
Jun 12, 2023, 2:38:28 AM6/12/23
to Redis DB
ERR Unexpected flag in script shebang: allow_cross_slot_keys
when I am trying to load the script that I have pasted via redis-cli , it is throwing this - ERR Unexpected flag in script shebang: allow_cross_slot_keys , when i 'm trying to load it via java code and use it , then i am getting cross slot error.

My use case is that , i can't keep parent and child both in same slot.

Please help. Provide some examples 

Thanks and Regards,
Sabya

Itamar Haber

unread,
Jun 18, 2023, 11:03:20 AM6/18/23
to Redis DB
Hello Sabya,

Please make sure that you use the correct flag.
The example and errors you've shared indicate that you're using an unknown flag, namely "allow_cross_slot_keys".
Per the documentation at https://redis.io/docs/manual/programmability/lua-api/#register-function, the flag's correct form is "allow-cross-slot-keys".

Cheers
Itamar

Viktor Söderqvist

unread,
Jul 3, 2023, 10:10:08 AM7/3/23
to redi...@googlegroups.com
Hello Sabya,

> My use case is that , i can't keep parent and child both in same slot.

I'm curious, how can you be sure these slots are on the same Redis node?
Are you using Cluster with only one shard?

Viktor


On 2023-06-12 08:38, Sabyasachi Sahoo wrote:
> ERR Unexpected flag in script shebang: allow_cross_slot_keys
> when I am trying to load the script that I have pasted via redis-cli ,
> it is throwing this - *ERR Unexpected flag in script shebang:
> allow_cross_slot_keys *, when i 'm trying to load it via java code and
> use it , then i am getting cross slot error.
>
> My use case is that , i can't keep parent and child both in same slot.
>
> Please help. Provide some examples
>
> Thanks and Regards,
> Sabya
>
> On Saturday, June 10, 2023 at 10:11:01 PM UTC+5:30 madely...@gmail.com
> wrote:
>
> Using scripts that cross slots is considered an anti-pattern in
> Redis. The flag you mentioned is mostly intended for compatibility
> with older scripts which might have been previously accessing cross
> slots, see
> https://redis.io/docs/manual/programmability/lua-api/#script_flags
> <https://redis.io/docs/manual/programmability/lua-api/#script_flags>. You should investigate if you can modify  your script to use hash tags to follow best practices.
>
> -Madelyn
> On Jun 8, 2023 at 8:50 PM -0700, Sotto Voce <speakso...@gmail.com>,
> wrote:
>> You mention "script" and "function", but it's not clear whether
>> you're talking about LUA scripts/functions invoked by the
>> EVAL/FCALL commands, or you're talking about ordinary key read and
>> write commands.  Are you working with LUA scripts or functions?
>>
>> On Thursday, June 8, 2023 at 6:00:34 AM UTC-7 Sabyasachi Sahoo wrote:
>>
>> Hello,
>> I want to perform some cross slot operations.
>> When I explored, I found that a flag(allow-cross-slot-keys)
>> was added in this PR -
>> https://github.com/redis/redis-doc/pull/1893/files
>> <https://github.com/redis/redis-doc/pull/1893/files>.
>> I tried to apply this flag in script as well as function but
>> no luck.
>> I am trying to do this via java app.
>> redis version - 7.0.11
>> client library - lettuce.
>>
>> I'm stuck for quite sometime now
>> Please help, thanks in advance.
>>
>> Thanks and Regards,
>> Sabya
>>
>> --
>> You received this message because you are subscribed to the Google
>> Groups "Redis DB" group.
>> To unsubscribe from this group and stop receiving emails from it,
>> send an email to redis-db+u...@googlegroups.com.
>> To view this discussion on the web visit
>> https://groups.google.com/d/msgid/redis-db/dc61a882-7a21-4ab9-978b-8638bda1d531n%40googlegroups.com <https://groups.google.com/d/msgid/redis-db/dc61a882-7a21-4ab9-978b-8638bda1d531n%40googlegroups.com?utm_medium=email&utm_source=footer>.
>
> --
> You received this message because you are subscribed to the Google
> Groups "Redis DB" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to redis-db+u...@googlegroups.com
> <mailto:redis-db+u...@googlegroups.com>.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/redis-db/8cf3cdd4-508a-4d93-bbb9-47a3317ae613n%40googlegroups.com <https://groups.google.com/d/msgid/redis-db/8cf3cdd4-508a-4d93-bbb9-47a3317ae613n%40googlegroups.com?utm_medium=email&utm_source=footer>.
Reply all
Reply to author
Forward
0 new messages