hirlite 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +15 -0
- data/LICENSE +28 -0
- data/Rakefile +51 -0
- data/ext/hirlite_ext/extconf.rb +33 -0
- data/ext/hirlite_ext/hirlite_ext.c +14 -0
- data/ext/hirlite_ext/hirlite_ext.h +38 -0
- data/ext/hirlite_ext/rlite.c +351 -0
- data/lib/hirlite/rlite.rb +1 -0
- data/lib/hirlite/version.rb +3 -0
- data/lib/hirlite.rb +2 -0
- data/vendor/rlite/Makefile +6 -0
- data/vendor/rlite/deps/crc64.c +191 -0
- data/vendor/rlite/deps/crc64.h +3 -0
- data/vendor/rlite/deps/endianconv.h +73 -0
- data/vendor/rlite/deps/hyperloglog.c +1547 -0
- data/vendor/rlite/deps/hyperloglog.h +14 -0
- data/vendor/rlite/deps/lzf.h +100 -0
- data/vendor/rlite/deps/lzfP.h +159 -0
- data/vendor/rlite/deps/lzf_c.c +295 -0
- data/vendor/rlite/deps/lzf_d.c +150 -0
- data/vendor/rlite/deps/sha1.c +227 -0
- data/vendor/rlite/deps/sha1.h +19 -0
- data/vendor/rlite/deps/utilfromredis.c +397 -0
- data/vendor/rlite/deps/utilfromredis.h +11 -0
- data/vendor/rlite/src/Makefile +79 -0
- data/vendor/rlite/src/constants.h +15 -0
- data/vendor/rlite/src/dump.c +191 -0
- data/vendor/rlite/src/dump.h +3 -0
- data/vendor/rlite/src/hirlite.c +3985 -0
- data/vendor/rlite/src/hirlite.h +186 -0
- data/vendor/rlite/src/page_btree.c +1556 -0
- data/vendor/rlite/src/page_btree.h +133 -0
- data/vendor/rlite/src/page_key.c +283 -0
- data/vendor/rlite/src/page_key.h +25 -0
- data/vendor/rlite/src/page_list.c +718 -0
- data/vendor/rlite/src/page_list.h +70 -0
- data/vendor/rlite/src/page_long.c +61 -0
- data/vendor/rlite/src/page_long.h +14 -0
- data/vendor/rlite/src/page_multi_string.c +538 -0
- data/vendor/rlite/src/page_multi_string.h +18 -0
- data/vendor/rlite/src/page_skiplist.c +689 -0
- data/vendor/rlite/src/page_skiplist.h +70 -0
- data/vendor/rlite/src/page_string.c +55 -0
- data/vendor/rlite/src/page_string.h +12 -0
- data/vendor/rlite/src/pqsort.c +185 -0
- data/vendor/rlite/src/pqsort.h +40 -0
- data/vendor/rlite/src/restore.c +401 -0
- data/vendor/rlite/src/restore.h +3 -0
- data/vendor/rlite/src/rlite.c +1309 -0
- data/vendor/rlite/src/rlite.h +159 -0
- data/vendor/rlite/src/sort.c +530 -0
- data/vendor/rlite/src/sort.h +18 -0
- data/vendor/rlite/src/status.h +19 -0
- data/vendor/rlite/src/type_hash.c +607 -0
- data/vendor/rlite/src/type_hash.h +29 -0
- data/vendor/rlite/src/type_list.c +477 -0
- data/vendor/rlite/src/type_list.h +23 -0
- data/vendor/rlite/src/type_set.c +796 -0
- data/vendor/rlite/src/type_set.h +34 -0
- data/vendor/rlite/src/type_string.c +613 -0
- data/vendor/rlite/src/type_string.h +34 -0
- data/vendor/rlite/src/type_zset.c +1147 -0
- data/vendor/rlite/src/type_zset.h +50 -0
- data/vendor/rlite/src/util.c +334 -0
- data/vendor/rlite/src/util.h +71 -0
- metadata +151 -0
@@ -0,0 +1,186 @@
|
|
1
|
+
#ifndef __HIRLITE_H
|
2
|
+
#define __HIRLITE_H
|
3
|
+
#include <stdio.h> /* for size_t */
|
4
|
+
#include <stdarg.h> /* for va_list */
|
5
|
+
#include <sys/time.h> /* for struct timeval */
|
6
|
+
|
7
|
+
#include "rlite.h"
|
8
|
+
|
9
|
+
#define HIRLITE_MAJOR 0
|
10
|
+
#define HIRLITE_MINOR 11
|
11
|
+
#define HIRLITE_PATCH 0
|
12
|
+
|
13
|
+
#define RLITE_ERR -1
|
14
|
+
#define RLITE_OK 0
|
15
|
+
|
16
|
+
/* When an error occurs, the err flag in a context is set to hold the type of
|
17
|
+
* error that occured. RLITE_ERR_IO means there was an I/O error and you
|
18
|
+
* should use the "errno" variable to find out what is wrong.
|
19
|
+
* For other values, the "errstr" field will hold a description. */
|
20
|
+
#define RLITE_ERR_IO 1 /* Error in read or write */
|
21
|
+
#define RLITE_ERR_EOF 3 /* End of file */
|
22
|
+
#define RLITE_ERR_PROTOCOL 4 /* Protocol error */
|
23
|
+
#define RLITE_ERR_OOM 5 /* Out of memory */
|
24
|
+
#define RLITE_ERR_OTHER 2 /* Everything else... */
|
25
|
+
|
26
|
+
/* Connection type can be blocking or non-blocking and is set in the
|
27
|
+
* least significant bit of the flags field in rliteContext. */
|
28
|
+
#define RLITE_BLOCK 0x1
|
29
|
+
|
30
|
+
/* Connection may be disconnected before being free'd. The second bit
|
31
|
+
* in the flags field is set when the context is connected. */
|
32
|
+
#define RLITE_CONNECTED 0x2
|
33
|
+
|
34
|
+
/* The async API might try to disconnect cleanly and flush the output
|
35
|
+
* buffer and read all subsequent replies before disconnecting.
|
36
|
+
* This flag means no new commands can come in and the connection
|
37
|
+
* should be terminated once all replies have been read. */
|
38
|
+
#define RLITE_DISCONNECTING 0x4
|
39
|
+
|
40
|
+
/* Flag specific to the async API which means that the context should be clean
|
41
|
+
* up as soon as possible. */
|
42
|
+
#define RLITE_FREEING 0x8
|
43
|
+
|
44
|
+
/* Flag that is set when an async callback is executed. */
|
45
|
+
#define RLITE_IN_CALLBACK 0x10
|
46
|
+
|
47
|
+
/* Flag that is set when the async context has one or more subscriptions. */
|
48
|
+
#define RLITE_SUBSCRIBED 0x20
|
49
|
+
|
50
|
+
/* Flag that is set when monitor mode is active */
|
51
|
+
#define RLITE_MONITORING 0x40
|
52
|
+
|
53
|
+
#define RLITE_REPLY_STRING 1
|
54
|
+
#define RLITE_REPLY_ARRAY 2
|
55
|
+
#define RLITE_REPLY_INTEGER 3
|
56
|
+
#define RLITE_REPLY_NIL 4
|
57
|
+
#define RLITE_REPLY_STATUS 5
|
58
|
+
#define RLITE_REPLY_ERROR 6
|
59
|
+
|
60
|
+
#define RLITE_READER_MAX_BUF (1024*16) /* Default max unused reader buffer. */
|
61
|
+
|
62
|
+
#define RLITE_KEEPALIVE_INTERVAL 15 /* seconds */
|
63
|
+
|
64
|
+
#ifdef __cplusplus
|
65
|
+
extern "C" {
|
66
|
+
#endif
|
67
|
+
|
68
|
+
struct rliteClient;
|
69
|
+
|
70
|
+
/* This is the reply object returned by rliteCommand() */
|
71
|
+
typedef struct rliteReply {
|
72
|
+
int type; /* RLITE_REPLY_* */
|
73
|
+
long long integer; /* The integer when type is RLITE_REPLY_INTEGER */
|
74
|
+
int len; /* Length of string */
|
75
|
+
char *str; /* Used for both RLITE_REPLY_ERROR and RLITE_REPLY_STRING */
|
76
|
+
size_t elements; /* number of elements, for RLITE_REPLY_ARRAY */
|
77
|
+
struct rliteReply **element; /* elements vector for RLITE_REPLY_ARRAY */
|
78
|
+
} rliteReply;
|
79
|
+
|
80
|
+
/* Function to free the reply objects hirlite returns by default. */
|
81
|
+
void rliteFreeReplyObject(void *reply);
|
82
|
+
|
83
|
+
/* Functions to format a command according to the protocol. */
|
84
|
+
int rlitevFormatCommand(struct rliteClient *client, const char *format, va_list ap);
|
85
|
+
int rliteFormatCommand(struct rliteClient *client, const char *format, ...);
|
86
|
+
int rliteFormatCommandArgv(struct rliteClient *client, int argc, char **argv, size_t *argvlen);
|
87
|
+
|
88
|
+
struct rliteClient;
|
89
|
+
|
90
|
+
/* Context for a connection to Redis */
|
91
|
+
typedef struct rliteContext {
|
92
|
+
int err; /* Error flags, 0 when there is no error */
|
93
|
+
char errstr[128]; /* String representation of error when applicable */
|
94
|
+
rliteReply **replies;
|
95
|
+
int replyPosition; // avoid reallocing the pointer after removing an element, keep a reference of the next position
|
96
|
+
int replyLength;
|
97
|
+
int replyAlloc;
|
98
|
+
rlite *db;
|
99
|
+
int debugSkiplist;
|
100
|
+
int cluster_enabled;
|
101
|
+
size_t hashtableLimitEntries;
|
102
|
+
size_t hashtableLimitValue;
|
103
|
+
void (*writeCommand)(int dbid, int argc, char **argv, size_t *argvlen);
|
104
|
+
|
105
|
+
short inTransaction;
|
106
|
+
short transactionFailed;
|
107
|
+
size_t watchedKeysAlloc;
|
108
|
+
size_t watchedKeysLength;
|
109
|
+
struct watched_key **watchedKeys;
|
110
|
+
size_t enqueuedCommandsAlloc;
|
111
|
+
size_t enqueuedCommandsLength;
|
112
|
+
struct rliteClient **enqueuedCommands;
|
113
|
+
} rliteContext;
|
114
|
+
|
115
|
+
rliteContext *rliteConnect(const char *ip, int port);
|
116
|
+
rliteContext *rliteConnectWithTimeout(const char *ip, int port, const struct timeval tv);
|
117
|
+
rliteContext *rliteConnectNonBlock(const char *ip, int port);
|
118
|
+
rliteContext *rliteConnectBindNonBlock(const char *ip, int port, const char *source_addr);
|
119
|
+
rliteContext *rliteConnectUnix(const char *path);
|
120
|
+
rliteContext *rliteConnectUnixWithTimeout(const char *path, const struct timeval tv);
|
121
|
+
rliteContext *rliteConnectUnixNonBlock(const char *path);
|
122
|
+
rliteContext *rliteConnectFd(int fd);
|
123
|
+
int rliteSetTimeout(rliteContext *c, const struct timeval tv);
|
124
|
+
int rliteEnableKeepAlive(rliteContext *c);
|
125
|
+
void rliteFree(rliteContext *c);
|
126
|
+
int rliteFreeKeepFd(rliteContext *c);
|
127
|
+
int rliteBufferRead(rliteContext *c);
|
128
|
+
int rliteBufferWrite(rliteContext *c, int *done);
|
129
|
+
|
130
|
+
/* In a blocking context, this function first checks if there are unconsumed
|
131
|
+
* replies to return and returns one if so. Otherwise, it flushes the output
|
132
|
+
* buffer to the socket and reads until it has a reply. In a non-blocking
|
133
|
+
* context, it will return unconsumed replies until there are no more. */
|
134
|
+
int rliteGetReply(rliteContext *c, void **reply);
|
135
|
+
int rliteGetReplyFromReader(rliteContext *c, void **reply);
|
136
|
+
|
137
|
+
/* Write a formatted command to the output buffer. Use these functions in blocking mode
|
138
|
+
* to get a pipeline of commands. */
|
139
|
+
int rliteAppendFormattedCommand(rliteContext *c, const char *cmd, size_t len);
|
140
|
+
|
141
|
+
/* Write a command to the output buffer. Use these functions in blocking mode
|
142
|
+
* to get a pipeline of commands. */
|
143
|
+
int rlitevAppendCommand(rliteContext *c, const char *format, va_list ap);
|
144
|
+
int rliteAppendCommand(rliteContext *c, const char *format, ...);
|
145
|
+
int rliteAppendCommandArgv(rliteContext *c, int argc, char **argv, size_t *argvlen);
|
146
|
+
|
147
|
+
/* Issue a command to Redis. In a blocking context, it is identical to calling
|
148
|
+
* rliteAppendCommand, followed by rliteGetReply. The function will return
|
149
|
+
* NULL if there was an error in performing the request, otherwise it will
|
150
|
+
* return the reply. In a non-blocking context, it is identical to calling
|
151
|
+
* only rliteAppendCommand and will always return NULL. */
|
152
|
+
void *rlitevCommand(rliteContext *c, const char *format, va_list ap);
|
153
|
+
void *rliteCommand(rliteContext *c, const char *format, ...);
|
154
|
+
void *rliteCommandArgv(rliteContext *c, int argc, char **argv, size_t *argvlen);
|
155
|
+
|
156
|
+
typedef struct rliteClient {
|
157
|
+
int argc;
|
158
|
+
char **argv;
|
159
|
+
size_t *argvlen;
|
160
|
+
rliteReply *reply;
|
161
|
+
rliteContext *context;
|
162
|
+
} rliteClient;
|
163
|
+
|
164
|
+
typedef void rliteCommandProc(rliteClient *c);
|
165
|
+
|
166
|
+
struct rliteCommand {
|
167
|
+
char *name;
|
168
|
+
rliteCommandProc *proc;
|
169
|
+
int arity;
|
170
|
+
char *sflags; /* Flags as string representation, one char per flag. */
|
171
|
+
int flags; /* The actual flags, obtained from the 'sflags' field. */
|
172
|
+
/* Use a function to determine keys arguments in a command line.
|
173
|
+
* Used for Redis Cluster redirect. */
|
174
|
+
// rliteGetKeysProc *getkeys_proc;
|
175
|
+
/* What keys should be loaded in background when calling this command? */
|
176
|
+
int firstkey; /* The first argument that's a key (0 = no keys) */
|
177
|
+
int lastkey; /* The last argument that's a key */
|
178
|
+
int keystep; /* The step between first and last key */
|
179
|
+
long long microseconds, calls;
|
180
|
+
};
|
181
|
+
|
182
|
+
#ifdef __cplusplus
|
183
|
+
}
|
184
|
+
#endif
|
185
|
+
|
186
|
+
#endif
|