Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

readonly mode commands #542

Open
skaravad opened this issue Oct 1, 2023 · 4 comments
Open

readonly mode commands #542

skaravad opened this issue Oct 1, 2023 · 4 comments
Labels
master fixed already fixed at master branch

Comments

@skaravad
Copy link

skaravad commented Oct 1, 2023

Hello,

We plan to use info and select commands in readonly mode , I'm not a nodeJs expert, any files that I can modify to make this happen ? currently when READ_ONLY is enabled, the INFO and SELECT commands return this

info keyspace
"ERROR: Command not read-only"
select 13
"ERROR: Command not read-only"
@skaravad
Copy link
Author

skaravad commented Oct 1, 2023

I attempted modifying
node_modules/@ioredis/commands/built/commands.json
node_modules/@ioredis/commands/commands.json

   "info": {
        "arity": -1,
        "flags": [
            "readonly",
            "loading",
            "stale"
        ],
        "keyStart": 0,
        "keyStop": 0,
        "step": 0
    },

@sseide
Copy link
Collaborator

sseide commented Oct 10, 2023

Hello,
the list of read-only commands is (where ever allowed by the server) queried directly from the server itself after connect. "COMMAND" is send and the output parsed for all commands having the property "readonly"

Example output for some commands:

61) 1) "select"
     2) (integer) 2
     3) 1) loading
        2) fast
     4) (integer) 0
     5) (integer) 0
     6) (integer) 0
...
86) 1) "dbsize"
     2) (integer) 1
     3) 1) readonly
        2) fast
     4) (integer) 0
     5) (integer) 0
     6) (integer) 0
...
137) 1) "cluster"
     2) (integer) -2
     3) 1) admin
     4) (integer) 0
     5) (integer) 0
     6) (integer) 0
138) 1) "flushdb"
     2) (integer) -1
     3) 1) write
     4) (integer) 0
     5) (integer) 0
     6) (integer) 0
...
140) 1) "info"
     2) (integer) -1
     3) 1) random
        2) loading
        3) stale
     4) (integer) 0
     5) (integer) 0
     6) (integer) 0

That is why (from this list) "dbsize" only is allowed but not "select" or "flushdb".

Maybe the selection criteria should be evaluated to allow info or similar too. But must be make sure to not open up to more dangerous commands...

@skaravad
Copy link
Author

thank you , will give it a try.

@sseide
Copy link
Collaborator

sseide commented Nov 22, 2023

Hello, i just added these two commands to a special list set as read-only on dynamic evaluation too.
Its done in master branch and "latest" docker image.

Can you give it a try? And are there more commands missing as read-only?

Now the list is defined as a configuration option and can be overwritten with whatever you like inside your local.json file. The fallback/default is defined in the default.json config.

@sseide sseide added the master fixed already fixed at master branch label Nov 22, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
master fixed already fixed at master branch
Projects
None yet
Development

No branches or pull requests

2 participants