Add updated version of Redis modules
[ric-plt/dbaas.git] / redismodule / tst / mock / include / redismodule.h
1 /*
2  * Copyright (c) 2018-2020 Nokia.
3  *
4  *   Licensed under the Apache License, Version 2.0 (the "License");
5  *   you may not use this file except in compliance with the License.
6  *   You may obtain a copy of the License at
7  *
8  *       http://www.apache.org/licenses/LICENSE-2.0
9  *
10  *   Unless required by applicable law or agreed to in writing, software
11  *   distributed under the License is distributed on an "AS IS" BASIS,
12  *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  *   See the License for the specific language governing permissions and
14  *   limitations under the License.
15  */
16
17 /*
18  * This source code is part of the near-RT RIC (RAN Intelligent Controller)
19  * platform project (RICP).
20  */
21
22 #ifndef REDISMODULE_H
23 #define REDISMODULE_H
24
25 #include <sys/types.h>
26 #include <stdint.h>
27 #include <stdio.h>
28
29 /* Error status return values. */
30 #define REDISMODULE_OK 0
31 #define REDISMODULE_ERR 1
32
33 /* API versions. */
34 #define REDISMODULE_APIVER_1 1
35
36 /* API flags and constants */
37 #define REDISMODULE_READ (1<<0)
38 #define REDISMODULE_WRITE (1<<1)
39
40 /* Key types. */
41 #define REDISMODULE_KEYTYPE_EMPTY 0
42 #define REDISMODULE_KEYTYPE_STRING 1
43 #define REDISMODULE_KEYTYPE_LIST 2
44 #define REDISMODULE_KEYTYPE_HASH 3
45 #define REDISMODULE_KEYTYPE_SET 4
46 #define REDISMODULE_KEYTYPE_ZSET 5
47 #define REDISMODULE_KEYTYPE_MODULE 6
48
49 /* Reply types. */
50 #define REDISMODULE_REPLY_UNKNOWN -1
51 #define REDISMODULE_REPLY_STRING 0
52 #define REDISMODULE_REPLY_ERROR 1
53 #define REDISMODULE_REPLY_INTEGER 2
54 #define REDISMODULE_REPLY_ARRAY 3
55 #define REDISMODULE_REPLY_NULL 4
56
57 /* Postponed array length. */
58 #define REDISMODULE_POSTPONED_ARRAY_LEN -1
59
60 /* Error messages. */
61 #define REDISMODULE_ERRORMSG_WRONGTYPE "WRONGTYPE Operation against a key holding the wrong kind of value"
62
63 #define REDISMODULE_NOT_USED(V) ((void) V)
64
65 typedef long long mstime_t;
66
67 /* UT dummy definitions for opaque redis types */
68 typedef struct { int dummy; } RedisModuleCtx;
69 typedef struct { int dummy; } RedisModuleKey;
70 typedef struct { int dummy; } RedisModuleString;
71 typedef struct { int dummy; } RedisModuleCallReply;
72 typedef struct { int dummy; } RedisModuleIO;
73 typedef struct { int dummy; } RedisModuleType;
74 typedef struct { int dummy; } RedisModuleDigest;
75 typedef struct { int dummy; } RedisModuleBlockedClient;
76
77 typedef void *(*RedisModuleTypeLoadFunc)(RedisModuleIO *rdb, int encver);
78 typedef void (*RedisModuleTypeSaveFunc)(RedisModuleIO *rdb, void *value);
79 typedef void (*RedisModuleTypeRewriteFunc)(RedisModuleIO *aof, RedisModuleString *key, void *value);
80 typedef size_t (*RedisModuleTypeMemUsageFunc)(const void *value);
81 typedef void (*RedisModuleTypeDigestFunc)(RedisModuleDigest *digest, void *value);
82 typedef void (*RedisModuleTypeFreeFunc)(void *value);
83
84 typedef int (*RedisModuleCmdFunc) (RedisModuleCtx *ctx, RedisModuleString **argv, int argc);
85
86 int RedisModule_CreateCommand(RedisModuleCtx *ctx, const char *name, RedisModuleCmdFunc cmdfunc, const char *strflags, int firstkey, int lastkey, int keystep);
87 int RedisModule_WrongArity(RedisModuleCtx *ctx);
88 int RedisModule_ReplyWithLongLong(RedisModuleCtx *ctx, long long ll);
89 void *RedisModule_OpenKey(RedisModuleCtx *ctx, RedisModuleString *keyname, int mode);
90 RedisModuleCallReply *RedisModule_Call(RedisModuleCtx *ctx, const char *cmdname, const char *fmt, ...);
91 void RedisModule_FreeCallReply(RedisModuleCallReply *reply);
92 int RedisModule_CallReplyType(RedisModuleCallReply *reply);
93 long long RedisModule_CallReplyInteger(RedisModuleCallReply *reply);
94 const char *RedisModule_StringPtrLen(const RedisModuleString *str, size_t *len);
95 int RedisModule_ReplyWithError(RedisModuleCtx *ctx, const char *err);
96 int RedisModule_ReplyWithString(RedisModuleCtx *ctx, RedisModuleString *str);
97 int RedisModule_ReplyWithNull(RedisModuleCtx *ctx);
98 int RedisModule_ReplyWithCallReply(RedisModuleCtx *ctx, RedisModuleCallReply *reply);
99 const char *RedisModule_CallReplyStringPtr(RedisModuleCallReply *reply, size_t *len);
100 RedisModuleString *RedisModule_CreateStringFromCallReply(RedisModuleCallReply *reply);
101
102 int RedisModule_KeyType(RedisModuleKey *kp);
103 void RedisModule_CloseKey(RedisModuleKey *kp);
104
105 int RedisModule_Init(RedisModuleCtx *ctx, const char *name, int ver, int apiver);
106
107 size_t RedisModule_CallReplyLength(RedisModuleCallReply *reply);
108 RedisModuleCallReply *RedisModule_CallReplyArrayElement(RedisModuleCallReply *reply, size_t idx);
109 int RedisModule_ReplyWithArray(RedisModuleCtx *ctx, long len);
110 void RedisModule_FreeString(RedisModuleCtx *ctx, RedisModuleString *str);
111 RedisModuleBlockedClient *RedisModule_BlockClient(RedisModuleCtx *ctx, RedisModuleCmdFunc reply_callback, RedisModuleCmdFunc timeout_callback, void (*free_privdata)(RedisModuleCtx*,void*), long long timeout_ms);
112 int RedisModule_UnblockClient(RedisModuleBlockedClient *bc, void *privdata);
113 int RedisModule_AbortBlock(RedisModuleBlockedClient *bc);
114 RedisModuleString *RedisModule_CreateString(RedisModuleCtx *ctx, const char *ptr, size_t len);
115 void RedisModule_FreeThreadSafeContext(RedisModuleCtx *ctx);
116 int RedisModule_StringToLongLong(const RedisModuleString *str, long long *ll);
117 void RedisModule_ThreadSafeContextLock(RedisModuleCtx *ctx);
118 void RedisModule_ThreadSafeContextUnlock(RedisModuleCtx *ctx);
119 void RedisModule_ReplySetArrayLength(RedisModuleCtx *ctx, long len);
120 RedisModuleCtx *RedisModule_GetThreadSafeContext(RedisModuleBlockedClient *bc);
121 RedisModuleString *RedisModule_CreateStringFromLongLong(RedisModuleCtx *ctx, long long ll);
122 void RedisModule_AutoMemory(RedisModuleCtx *ctx);
123 void *RedisModule_Alloc(size_t bytes);
124 void RedisModule_Free(void *ptr);
125
126 #endif /* REDISMODULE_H */