-
Notifications
You must be signed in to change notification settings - Fork 65
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
The PR introduce a new proc macro for command registrations. #326
Merged
Commits on May 7, 2023
-
The PR introduce a new proc macro for command registrations.
The PR introduce a new proc macro for command registrations with the new command registration API that was introduced on Redis 7. The new proc macro are called `redis_command`, The following command will register the `test_command` function as a Redis command called `foo`: ```rust #[redis_command( { name: "foo", arity: 3, key_spec: [ { notes: "some notes", flags: ["RW", "ACCESS"], begin_search: Keyword(("foo", 1)), find_keys: Range((1, 2, 3)), } ] } )] fn test_command(_ctx: &Context, _args: Vec<RedisString>) -> RedisResult { Ok(RedisValue::SimpleStringStatic("OK")) } ``` The supported properties are: * name - The command name, * flags (optional) - Command flags such as `readonly`, for the full list please refer to https://redis.io/docs/reference/modules/modules-api-ref/#redismodule_createcommand * summary (optional) - Command summary * complexity (optional) - Command compexity * since (optional) - At which module version the command was first introduce * tips (optional) - Command tips for proxy, for more information please refer to https://redis.io/topics/command-tips * arity - Number of arguments, including the command name itself. A positive number specifies an exact number of arguments and a negative number specifies a minimum number of arguments. * key_spec - A list of specs representing how to find the keys that the command might touch. the following options are available: * notes (optional) - Some note about the key spec. * flags - List of flags reprenting how the keys are accessed, the following options are available: * RO - Read-Only. Reads the value of the key, but doesn't necessarily return it. * RW - Read-Write. Modifies the data stored in the value of the key or its metadata. * OW - Overwrite. Overwrites the data stored in the value of the key. * RM - Deletes the key. * ACCESS - Returns, copies or uses the user data from the value of the key. * UPDATE - Updates data to the value, new value may depend on the old value. * INSERT - Adds data to the value with no chance of modification or deletion of existing data. * DELETE - Explicitly deletes some content from the value of the key. * NOT_KEY - The key is not actually a key, but should be routed in cluster mode as if it was a key. * INCOMPLETE - The keyspec might not point out all the keys it should cover. * VARIABLE_FLAGS - Some keys might have different flags depending on arguments. * begin_search - Represents how Redis should start looking for keys.There are 2 possible options: * Index - start looking for keys from a given position. * Keyword - Search for a specific keyward and start looking for keys from this keyword * FindKeys - After Redis finds the location from where it needs to start looking for keys, Redis will start finding keys base on the information in this struct. There are 2 possible options: * Range - A tuple represent a range of `(last_key, steps, limit)`. * last_key - Index of the last key relative to the result of the begin search step. Can be negative, in which case it's not relative. -1 indicates the last argument, -2 one before the last and so on. * steps - How many arguments should we skip after finding a key, in order to find the next one. * limit - If `lastkey` is -1, we use `limit` to stop the search by a factor. 0 and 1 mean no limit. 2 means 1/2 of the remaining args, 3 means 1/3, and so on. * Keynum - A tuple of 3 elements `(keynumidx, firstkey, keystep)`. * keynumidx - Index of the argument containing the number of keys to come, relative to the result of the begin search step. * firstkey - Index of the fist key relative to the result of thebegin search step. (Usually it's just after `keynumidx`, inwhich case it should be set to `keynumidx + 1`.) * keystep - How many arguments should we skip after finding a key, in order to find the next one? **Notice**, by default Redis does not validate the command spec. User should validate the command keys on the module command code. The command spec is used for validation on cluster so Redis can raise a cross slot error when needed. Ideas for future extension: * The proc macro can analyze the function inputs and generate a code for parsing the command arguments so that the command function will not have to deal with it.
Configuration menu - View commit details
-
Copy full SHA for 13101c0 - Browse repository at this point
Copy the full SHA 13101c0View commit details
Commits on May 11, 2023
-
Configuration menu - View commit details
-
Copy full SHA for 3e60de5 - Browse repository at this point
Copy the full SHA 3e60de5View commit details -
Configuration menu - View commit details
-
Copy full SHA for 33a9b8f - Browse repository at this point
Copy the full SHA 33a9b8fView commit details
Commits on May 13, 2023
-
Configuration menu - View commit details
-
Copy full SHA for 13f8f02 - Browse repository at this point
Copy the full SHA 13f8f02View commit details
Commits on May 14, 2023
-
Configuration menu - View commit details
-
Copy full SHA for 4e87b57 - Browse repository at this point
Copy the full SHA 4e87b57View commit details -
Configuration menu - View commit details
-
Copy full SHA for 45f32e1 - Browse repository at this point
Copy the full SHA 45f32e1View commit details -
Configuration menu - View commit details
-
Copy full SHA for c0a9445 - Browse repository at this point
Copy the full SHA c0a9445View commit details
Commits on May 15, 2023
-
Configuration menu - View commit details
-
Copy full SHA for 4637e68 - Browse repository at this point
Copy the full SHA 4637e68View commit details -
Configuration menu - View commit details
-
Copy full SHA for dee47ba - Browse repository at this point
Copy the full SHA dee47baView commit details -
Configuration menu - View commit details
-
Copy full SHA for e233378 - Browse repository at this point
Copy the full SHA e233378View commit details -
Configuration menu - View commit details
-
Copy full SHA for d1f3e00 - Browse repository at this point
Copy the full SHA d1f3e00View commit details -
Configuration menu - View commit details
-
Copy full SHA for 5356990 - Browse repository at this point
Copy the full SHA 5356990View commit details -
Configuration menu - View commit details
-
Copy full SHA for c8e55e0 - Browse repository at this point
Copy the full SHA c8e55e0View commit details
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.