valkey/tests/modules
Huang Zhw c81813148b
Add a special notification unlink available only for modules (#9406)
Add a new module event `RedisModule_Event_Key`, this event is fired
when a key is removed from the keyspace.
The event includes an open key that can be used for reading the key before
it is removed. Modules can also extract the key-name, and use RM_Open
or RM_Call to access key from within that event, but shouldn't modify anything
from within this event.

The following sub events are available:
  - `REDISMODULE_SUBEVENT_KEY_DELETED`
  - `REDISMODULE_SUBEVENT_KEY_EXPIRED`
  - `REDISMODULE_SUBEVENT_KEY_EVICTED`
  - `REDISMODULE_SUBEVENT_KEY_OVERWRITE`

The data pointer can be casted to a RedisModuleKeyInfo structure
with the following fields:
```
     RedisModuleKey *key;    // Opened Key
 ```

### internals

* We also add two dict functions:
  `dictTwoPhaseUnlinkFind` finds an element from the table, also get the plink of the entry.
  The entry is returned if the element is found. The user should later call `dictTwoPhaseUnlinkFree`
  with it in order to unlink and release it. Otherwise if the key is not found, NULL is returned.
  These two functions should be used in pair. `dictTwoPhaseUnlinkFind` pauses rehash and
  `dictTwoPhaseUnlinkFree` resumes rehash.
* We change `dbOverwrite` to `dbReplaceValue` which just replaces the value of the key and
  doesn't fire any events. The "overwrite" part (which emits events) is just when called from `setKey`,
  the other places that called dbOverwrite were ones that just update the value in-place (INCR*, SPOP,
  and dbUnshareStringValue). This should not have any real impact since `moduleNotifyKeyUnlink` and
  `signalDeletedKeyAsReady` wouldn't have mattered in these cases anyway (i.e. module keys and
  stream keys didn't have direct calls to dbOverwrite)
* since we allow doing RM_OpenKey from withing these callbacks, we temporarily disable lazy expiry.
* We also temporarily disable lazy expiry when we are in unlink/unlink2 callback and keyspace 
  notification callback.
* Move special definitions to the top of redismodule.h
  This is needed to resolve compilation errors with RedisModuleKeyInfoV1
  that carries a RedisModuleKey member.

Co-authored-by: Oran Agra <oran@redislabs.com>
2022-11-30 11:56:36 +02:00
..
aclcheck.c Allow specifying ACL reason for module log entry (#10559) 2022-04-11 22:16:17 -07:00
auth.c Add module API for redacting command arguments (#10425) 2022-03-15 18:21:13 -07:00
basics.c Fix crash on RM_Call inside module load (#11346) 2022-10-12 13:09:51 +03:00
blockedclient.c Fix crash on RM_Call with script mode. (#10886) 2022-06-21 10:01:13 +03:00
blockonbackground.c Modules: Mark all APIs non-experimental (#9983) 2021-12-30 12:17:22 +02:00
blockonkeys.c Blocked module clients should be aware when a key is deleted (#11310) 2022-10-18 19:50:02 +03:00
cmdintrospection.c Repurpose redisCommandArg's name as the unique ID (#11051) 2022-08-18 15:09:36 +03:00
commandfilter.c Modules: Mark all APIs non-experimental (#9983) 2021-12-30 12:17:22 +02:00
datatype2.c Use const char pointer in redismodule.h as far as possible (#10064) 2022-01-18 15:55:20 +02:00
datatype.c Adding module api for processing commands during busy jobs and allow flagging the commands that should be handled at this status (#9963) 2022-01-20 09:05:53 +02:00
defragtest.c Build TLS as a loadable module 2022-08-23 12:37:56 +03:00
eventloop.c delete obsolete REDISMODULE_EXPERIMENTAL_API define in module demos (#10527) 2022-04-05 08:21:41 +03:00
fork.c Fix race in module fork kill test (#10717) 2022-05-12 20:10:38 +03:00
getchannels.c Implemented module getchannels api and renamed channel keyspec (#10299) 2022-02-22 11:00:03 +02:00
getkeys.c Handle key-spec flags with modules (#10237) 2022-02-08 10:01:35 +02:00
hash.c Sort out the mess around writable replicas and lookupKeyRead/Write (#9572) 2021-11-28 11:26:28 +02:00
hooks.c Add a special notification unlink available only for modules (#9406) 2022-11-30 11:56:36 +02:00
infotest.c
keyspace_events.c Module API to allow writes after key space notification hooks (#11199) 2022-11-24 19:00:04 +02:00
keyspecs.c RM_CreateCommand should not set CMD_KEY_VARIABLE_FLAGS automatically (#11320) 2022-09-28 14:15:07 +03:00
list.c Fix crash due to to reuse iterator entry after list deletion in module (#11383) 2022-10-22 20:36:50 +03:00
Makefile Module API to allow writes after key space notification hooks (#11199) 2022-11-24 19:00:04 +02:00
mallocsize.c Add RM_MallocSizeString, RM_MallocSizeDict (#10542) 2022-04-17 08:31:57 +03:00
misc.c Add missing REDISMODULE_CLIENTINFO_INITIALIZER (#10885) 2022-06-27 08:29:05 +03:00
moduleconfigs.c Bug fixes for enum configs with overlapping bit flags (module API) (#10661) 2022-05-09 13:36:53 +03:00
moduleconfigstwo.c Module Configurations (#10285) 2022-03-30 15:47:06 +03:00
postnotifications.c Module API to allow writes after key space notification hooks (#11199) 2022-11-24 19:00:04 +02:00
propagate.c sub-command support for ACL CAT and COMMAND LIST. redisCommand always stores fullname (#10127) 2022-01-23 10:05:06 +02:00
publish.c Add RM_PublishMessageShard (#10543) 2022-04-17 15:43:22 +03:00
reply.c Add test to cover NAN reply using a module (#11482) 2022-11-13 13:12:22 +02:00
scan.c Replace deprecated REDISMODULE_POSTPONED_ARRAY_LEN in module tests and examples (#9677) 2021-10-25 12:00:43 +03:00
stream.c Sort out the mess around writable replicas and lookupKeyRead/Write (#9572) 2021-11-28 11:26:28 +02:00
subcommands.c Block some specific characters in module command names (#11434) 2022-11-03 13:19:49 +02:00
test_lazyfree.c Sort out the mess around writable replicas and lookupKeyRead/Write (#9572) 2021-11-28 11:26:28 +02:00
testrdb.c Avoid saving module aux on RDB if no aux data was saved by the module. (#11374) 2022-10-18 19:45:46 +03:00
timer.c Modules: Mark all APIs non-experimental (#9983) 2021-12-30 12:17:22 +02:00
usercall.c Add RM_SetContextUser to support acl validation in RM_Call (and scripts) (#10966) 2022-09-22 16:29:00 +03:00
zset.c Sort out the mess around writable replicas and lookupKeyRead/Write (#9572) 2021-11-28 11:26:28 +02:00