3636#include <unistd.h>
3737
3838// A simple global user
39- static RedisModuleUser * global ;
39+ static ValkeyModuleUser * global ;
4040static uint64_t global_auth_client_id = 0 ;
4141
4242/* HELLOACL.REVOKE
4343 * Synchronously revoke access from a user. */
44- int RevokeCommand_RedisCommand ( RedisModuleCtx * ctx , RedisModuleString * * argv , int argc ) {
44+ int RevokeCommand_ValkeyCommand ( ValkeyModuleCtx * ctx , ValkeyModuleString * * argv , int argc ) {
4545 VALKEYMODULE_NOT_USED (argv );
4646 VALKEYMODULE_NOT_USED (argc );
4747
4848 if (global_auth_client_id ) {
49- RedisModule_DeauthenticateAndCloseClient (ctx , global_auth_client_id );
50- return RedisModule_ReplyWithSimpleString (ctx , "OK" );
49+ ValkeyModule_DeauthenticateAndCloseClient (ctx , global_auth_client_id );
50+ return ValkeyModule_ReplyWithSimpleString (ctx , "OK" );
5151 } else {
52- return RedisModule_ReplyWithError (ctx , "Global user currently not used" );
52+ return ValkeyModule_ReplyWithError (ctx , "Global user currently not used" );
5353 }
5454}
5555
5656/* HELLOACL.RESET
5757 * Synchronously delete and re-create a module user. */
58- int ResetCommand_RedisCommand ( RedisModuleCtx * ctx , RedisModuleString * * argv , int argc ) {
58+ int ResetCommand_ValkeyCommand ( ValkeyModuleCtx * ctx , ValkeyModuleString * * argv , int argc ) {
5959 VALKEYMODULE_NOT_USED (argv );
6060 VALKEYMODULE_NOT_USED (argc );
6161
62- RedisModule_FreeModuleUser (global );
63- global = RedisModule_CreateModuleUser ("global" );
64- RedisModule_SetModuleUserACL (global , "allcommands" );
65- RedisModule_SetModuleUserACL (global , "allkeys" );
66- RedisModule_SetModuleUserACL (global , "on" );
62+ ValkeyModule_FreeModuleUser (global );
63+ global = ValkeyModule_CreateModuleUser ("global" );
64+ ValkeyModule_SetModuleUserACL (global , "allcommands" );
65+ ValkeyModule_SetModuleUserACL (global , "allkeys" );
66+ ValkeyModule_SetModuleUserACL (global , "on" );
6767
68- return RedisModule_ReplyWithSimpleString (ctx , "OK" );
68+ return ValkeyModule_ReplyWithSimpleString (ctx , "OK" );
6969}
7070
7171/* Callback handler for user changes, use this to notify a module of
@@ -78,111 +78,111 @@ void HelloACL_UserChanged(uint64_t client_id, void *privdata) {
7878
7979/* HELLOACL.AUTHGLOBAL
8080 * Synchronously assigns a module user to the current context. */
81- int AuthGlobalCommand_RedisCommand ( RedisModuleCtx * ctx , RedisModuleString * * argv , int argc ) {
81+ int AuthGlobalCommand_ValkeyCommand ( ValkeyModuleCtx * ctx , ValkeyModuleString * * argv , int argc ) {
8282 VALKEYMODULE_NOT_USED (argv );
8383 VALKEYMODULE_NOT_USED (argc );
8484
8585 if (global_auth_client_id ) {
86- return RedisModule_ReplyWithError (ctx , "Global user currently used" );
86+ return ValkeyModule_ReplyWithError (ctx , "Global user currently used" );
8787 }
8888
89- RedisModule_AuthenticateClientWithUser (ctx , global , HelloACL_UserChanged , NULL , & global_auth_client_id );
89+ ValkeyModule_AuthenticateClientWithUser (ctx , global , HelloACL_UserChanged , NULL , & global_auth_client_id );
9090
91- return RedisModule_ReplyWithSimpleString (ctx , "OK" );
91+ return ValkeyModule_ReplyWithSimpleString (ctx , "OK" );
9292}
9393
9494#define TIMEOUT_TIME 1000
9595
9696/* Reply callback for auth command HELLOACL.AUTHASYNC */
97- int HelloACL_Reply (RedisModuleCtx * ctx , RedisModuleString * * argv , int argc ) {
97+ int HelloACL_Reply (ValkeyModuleCtx * ctx , ValkeyModuleString * * argv , int argc ) {
9898 VALKEYMODULE_NOT_USED (argv );
9999 VALKEYMODULE_NOT_USED (argc );
100100 size_t length ;
101101
102- RedisModuleString * user_string = RedisModule_GetBlockedClientPrivateData (ctx );
103- const char * name = RedisModule_StringPtrLen (user_string , & length );
102+ ValkeyModuleString * user_string = ValkeyModule_GetBlockedClientPrivateData (ctx );
103+ const char * name = ValkeyModule_StringPtrLen (user_string , & length );
104104
105- if (RedisModule_AuthenticateClientWithACLUser (ctx , name , length , NULL , NULL , NULL ) ==
105+ if (ValkeyModule_AuthenticateClientWithACLUser (ctx , name , length , NULL , NULL , NULL ) ==
106106 VALKEYMODULE_ERR ) {
107- return RedisModule_ReplyWithError (ctx , "Invalid Username or password" );
107+ return ValkeyModule_ReplyWithError (ctx , "Invalid Username or password" );
108108 }
109- return RedisModule_ReplyWithSimpleString (ctx , "OK" );
109+ return ValkeyModule_ReplyWithSimpleString (ctx , "OK" );
110110}
111111
112112/* Timeout callback for auth command HELLOACL.AUTHASYNC */
113- int HelloACL_Timeout (RedisModuleCtx * ctx , RedisModuleString * * argv , int argc ) {
113+ int HelloACL_Timeout (ValkeyModuleCtx * ctx , ValkeyModuleString * * argv , int argc ) {
114114 VALKEYMODULE_NOT_USED (argv );
115115 VALKEYMODULE_NOT_USED (argc );
116- return RedisModule_ReplyWithSimpleString (ctx , "Request timedout" );
116+ return ValkeyModule_ReplyWithSimpleString (ctx , "Request timedout" );
117117}
118118
119119/* Private data frees data for HELLOACL.AUTHASYNC command. */
120- void HelloACL_FreeData (RedisModuleCtx * ctx , void * privdata ) {
120+ void HelloACL_FreeData (ValkeyModuleCtx * ctx , void * privdata ) {
121121 VALKEYMODULE_NOT_USED (ctx );
122- RedisModule_FreeString (NULL , privdata );
122+ ValkeyModule_FreeString (NULL , privdata );
123123}
124124
125125/* Background authentication can happen here. */
126126void * HelloACL_ThreadMain (void * args ) {
127127 void * * targs = args ;
128- RedisModuleBlockedClient * bc = targs [0 ];
129- RedisModuleString * user = targs [1 ];
130- RedisModule_Free (targs );
128+ ValkeyModuleBlockedClient * bc = targs [0 ];
129+ ValkeyModuleString * user = targs [1 ];
130+ ValkeyModule_Free (targs );
131131
132- RedisModule_UnblockClient (bc ,user );
132+ ValkeyModule_UnblockClient (bc ,user );
133133 return NULL ;
134134}
135135
136136/* HELLOACL.AUTHASYNC
137137 * Asynchronously assigns an ACL user to the current context. */
138- int AuthAsyncCommand_RedisCommand ( RedisModuleCtx * ctx , RedisModuleString * * argv , int argc ) {
139- if (argc != 2 ) return RedisModule_WrongArity (ctx );
138+ int AuthAsyncCommand_ValkeyCommand ( ValkeyModuleCtx * ctx , ValkeyModuleString * * argv , int argc ) {
139+ if (argc != 2 ) return ValkeyModule_WrongArity (ctx );
140140
141141 pthread_t tid ;
142- RedisModuleBlockedClient * bc = RedisModule_BlockClient (ctx , HelloACL_Reply , HelloACL_Timeout , HelloACL_FreeData , TIMEOUT_TIME );
142+ ValkeyModuleBlockedClient * bc = ValkeyModule_BlockClient (ctx , HelloACL_Reply , HelloACL_Timeout , HelloACL_FreeData , TIMEOUT_TIME );
143143
144144
145- void * * targs = RedisModule_Alloc (sizeof (void * )* 2 );
145+ void * * targs = ValkeyModule_Alloc (sizeof (void * )* 2 );
146146 targs [0 ] = bc ;
147- targs [1 ] = RedisModule_CreateStringFromString (NULL , argv [1 ]);
147+ targs [1 ] = ValkeyModule_CreateStringFromString (NULL , argv [1 ]);
148148
149149 if (pthread_create (& tid , NULL , HelloACL_ThreadMain , targs ) != 0 ) {
150- RedisModule_AbortBlock (bc );
151- return RedisModule_ReplyWithError (ctx , "-ERR Can't start thread" );
150+ ValkeyModule_AbortBlock (bc );
151+ return ValkeyModule_ReplyWithError (ctx , "-ERR Can't start thread" );
152152 }
153153
154154 return VALKEYMODULE_OK ;
155155}
156156
157- /* This function must be present on each Redis module. It is used in order to
158- * register the commands into the Redis server. */
159- int RedisModule_OnLoad ( RedisModuleCtx * ctx , RedisModuleString * * argv , int argc ) {
157+ /* This function must be present on each Valkey module. It is used in order to
158+ * register the commands into the Valkey server. */
159+ int ValkeyModule_OnLoad ( ValkeyModuleCtx * ctx , ValkeyModuleString * * argv , int argc ) {
160160 VALKEYMODULE_NOT_USED (argv );
161161 VALKEYMODULE_NOT_USED (argc );
162162
163- if (RedisModule_Init (ctx ,"helloacl" ,1 ,VALKEYMODULE_APIVER_1 )
163+ if (ValkeyModule_Init (ctx ,"helloacl" ,1 ,VALKEYMODULE_APIVER_1 )
164164 == VALKEYMODULE_ERR ) return VALKEYMODULE_ERR ;
165165
166- if (RedisModule_CreateCommand (ctx ,"helloacl.reset" ,
167- ResetCommand_RedisCommand ,"" ,0 ,0 ,0 ) == VALKEYMODULE_ERR )
166+ if (ValkeyModule_CreateCommand (ctx ,"helloacl.reset" ,
167+ ResetCommand_ValkeyCommand ,"" ,0 ,0 ,0 ) == VALKEYMODULE_ERR )
168168 return VALKEYMODULE_ERR ;
169169
170- if (RedisModule_CreateCommand (ctx ,"helloacl.revoke" ,
171- RevokeCommand_RedisCommand ,"" ,0 ,0 ,0 ) == VALKEYMODULE_ERR )
170+ if (ValkeyModule_CreateCommand (ctx ,"helloacl.revoke" ,
171+ RevokeCommand_ValkeyCommand ,"" ,0 ,0 ,0 ) == VALKEYMODULE_ERR )
172172 return VALKEYMODULE_ERR ;
173173
174- if (RedisModule_CreateCommand (ctx ,"helloacl.authglobal" ,
175- AuthGlobalCommand_RedisCommand ,"no-auth" ,0 ,0 ,0 ) == VALKEYMODULE_ERR )
174+ if (ValkeyModule_CreateCommand (ctx ,"helloacl.authglobal" ,
175+ AuthGlobalCommand_ValkeyCommand ,"no-auth" ,0 ,0 ,0 ) == VALKEYMODULE_ERR )
176176 return VALKEYMODULE_ERR ;
177177
178- if (RedisModule_CreateCommand (ctx ,"helloacl.authasync" ,
179- AuthAsyncCommand_RedisCommand ,"no-auth" ,0 ,0 ,0 ) == VALKEYMODULE_ERR )
178+ if (ValkeyModule_CreateCommand (ctx ,"helloacl.authasync" ,
179+ AuthAsyncCommand_ValkeyCommand ,"no-auth" ,0 ,0 ,0 ) == VALKEYMODULE_ERR )
180180 return VALKEYMODULE_ERR ;
181181
182- global = RedisModule_CreateModuleUser ("global" );
183- RedisModule_SetModuleUserACL (global , "allcommands" );
184- RedisModule_SetModuleUserACL (global , "allkeys" );
185- RedisModule_SetModuleUserACL (global , "on" );
182+ global = ValkeyModule_CreateModuleUser ("global" );
183+ ValkeyModule_SetModuleUserACL (global , "allcommands" );
184+ ValkeyModule_SetModuleUserACL (global , "allkeys" );
185+ ValkeyModule_SetModuleUserACL (global , "on" );
186186
187187 global_auth_client_id = 0 ;
188188
0 commit comments