redis / redis-doc

Redis documentation source code for markdown and metadata files, conversion scripts, and so forth
Other
2.31k stars 1.72k forks source link

Redis Lua API reference #2183

Closed ambarsarkar closed 10 months ago

ambarsarkar commented 2 years ago

Seeking clarification:

What should redis.call('HGET'.. ) translate to when no entry exists.. nil or false? The return type is a bulk string reply.

In this page, it says null bulk and null multi-bulk replies are converted to false.

RESP2 null bulk reply and null multi bulk reply -> Lua false boolean type

I am confused since from: https://redis.io/docs/reference/protocol-spec/, :

This is called a Null Bulk String.

The client library API should not return an empty string, **but a nil object,** when the server replies with a Null Bulk String.

Thanks!

itamarhaber commented 2 years ago

Hello @ambarsarkar

I'm not entirely clear about the confusion - as you've noted the docs say that when redis.call returns a Redis null, it is cast to a Boolean false in Lua.

Let's test it out with redis-cli:

127.0.0.1:6379> HSET myhash myfield myval
(integer) 1
127.0.0.1:6379> EVAL "return type(redis.call('HGET', KEYS[1], ARGV[1]))" 1 myhash myfield
"string"
127.0.0.1:6379> EVAL "return type(redis.call('HGET', KEYS[1], ARGV[1]))" 1 myhash notafield
"boolean"
127.0.0.1:6379> EVAL "return type(redis.call('HGET', KEYS[1], ARGV[1]))" 1 notahash notafield
"boolean"

I hope this clarifies the matter.

ambarsarkar commented 2 years ago

Thanks for the tip on confirming the return type. The confusion is for two reasons:

  1. RESP2 to Lua type conversion says it's a false(boolean) for

The get response is a single object which is of bulk string type. The term "bulk reply" implied to response such as for arrays etc.

  1. RESP3 clearly switches to null for all nil:

Between the two, I got confused.. Maybe just explicitly mentioning bulk strings in RESP2 will remove that confusion

On Mon, Oct 31, 2022 at 6:02 AM Itamar Haber @.***> wrote:

Hello @ambarsarkar https://github.com/ambarsarkar

I'm not entirely clear about the confusion - as you've noted the docs say that when redis.call returns a Redis null, it is cast to a Boolean false in Lua.

Let's test it out with redis-cli:

127.0.0.1:6379> HSET myhash myfield myval (integer) 1127.0.0.1:6379> EVAL "return type(redis.call('HGET', KEYS[1], ARGV[1]))" 1 myhash myfield "string"127.0.0.1:6379> EVAL "return type(redis.call('HGET', KEYS[1], ARGV[1]))" 1 myhash notafield "boolean"127.0.0.1:6379> EVAL "return type(redis.call('HGET', KEYS[1], ARGV[1]))" 1 notahash notafield "boolean"

I hope this clarifies the matter.

— Reply to this email directly, view it on GitHub https://github.com/redis/redis-doc/issues/2183#issuecomment-1296859883, or unsubscribe https://github.com/notifications/unsubscribe-auth/AC4DZWHSTJC2G2PXMLN4JO3WF6KMNANCNFSM6AAAAAARQBM7SI . You are receiving this because you were mentioned.Message ID: @.***>

-- Ambar Sarkar: @.*** Skype: ambar.sarkar

itamarhaber commented 2 years ago

@ambarsarkar would you like to submit a PR that fixes this?

ambarsarkar commented 2 years ago

Sure.. What's the best way to do so? Thanks!

On Sun, Nov 6, 2022 at 9:15 AM Itamar Haber @.***> wrote:

@ambarsarkar https://github.com/ambarsarkar would you like to submit a PR that fixes this?

— Reply to this email directly, view it on GitHub https://github.com/redis/redis-doc/issues/2183#issuecomment-1304811589, or unsubscribe https://github.com/notifications/unsubscribe-auth/AC4DZWGE6A2JZX32SYKIBLTWG64PFANCNFSM6AAAAAARQBM7SI . You are receiving this because you were mentioned.Message ID: @.***>

-- Ambar Sarkar: @.*** Skype: ambar.sarkar

nermiller commented 2 years ago

@ambarsarkar you can clone the repo, edit the file, and commit the change. Let me know if you need further assistance. Thank you for your help!

ambarsarkar commented 1 year ago

Great. Will do this soon. Thanks for the hints.

On Thu, Nov 10, 2022 at 3:33 PM Nermina Miller @.***> wrote:

@ambarsarkar https://github.com/ambarsarkar you can clone the repo, edit the file, and commit the change. Let me know if you need further assistance. Thank you for your help!

— Reply to this email directly, view it on GitHub https://github.com/redis/redis-doc/issues/2183#issuecomment-1310861793, or unsubscribe https://github.com/notifications/unsubscribe-auth/AC4DZWG5S3OIIB5VMC5LJYDWHVL2TANCNFSM6AAAAAARQBM7SI . You are receiving this because you were mentioned.Message ID: @.***>

-- Ambar Sarkar: @.*** Skype: ambar.sarkar

mich-elle-luna commented 10 months ago

bulk strings are now included in https://redis.io/docs/reference/protocol-spec/ with the differences between resp2/3, closing as complete