You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Jul 11, 2021. It is now read-only.
Copy file name to clipboardExpand all lines: README.md
+130-81
Original file line number
Diff line number
Diff line change
@@ -12,9 +12,19 @@ Even basic SQL is very powerful and years upon years of experience on several SQ
12
12
13
13
Between all the SQL implementation, the one that best fitted the need for this module is definitely SQLite, for its velocity, portability, simplicity and capability to work in memory.
14
14
15
-
## Usage
15
+
## Getting start
16
16
17
-
You can get started simply downloading the git repo:
17
+
You can download the `.so` directly from github following the [release link](https://github.com/RedBeardLab/rediSQL/releases)
18
+
19
+
With the `.so` you can start redis passing the object as argument like so:
20
+
21
+
```
22
+
./redis-server --loadmodule librediSQL.so
23
+
```
24
+
25
+
## Compiling and contributing
26
+
27
+
If you want to compile the module yourself or contribute to the project you can simply clone the repo
6833:M 15 Dec 16:25:53.197 * The server is now ready to accept connections on port 6379
60
72
```
61
73
62
-
## API
63
-
64
-
### REDISQL.SQLITE_VERSION
65
-
66
-
This function reply with the version of SQLite that is actually in use.
67
-
68
-
```
69
-
127.0.0.1:6379> REDISQL.SQLITE_VERSION
70
-
3.15.1
71
-
```
72
-
73
-
### REDISQL.CREATE_DB key
74
-
75
-
This function will create a new SQLite database that will be bound to `key`.
76
-
77
-
```
78
-
127.0.0.1:6379> REDISQL.CREATE_DB user
79
-
OK
80
-
```
81
-
82
-
### REDISQL.EXEC key statement
83
-
84
-
This command will execute the statement against the database bound to `key`.
85
-
86
-
```
87
-
$ ./redis-cli
88
-
127.0.0.1:6379> REDISQL.CREATE_DB user
89
-
OK
90
-
91
-
$ ./redis-cli
92
-
127.0.0.1:6379> REDISQL.EXEC user "CREATE TABLE user(email TEXT, password TEXT)"
93
-
OK
94
-
127.0.0.1:6379> REDISQL.EXEC user "INSERT INTO user VALUES('test@test.it','very secret')"
95
-
OK
96
-
127.0.0.1:6379> REDISQL.EXEC user "INSERT INTO user VALUES('noob@security.io', 'password')"
97
-
OK
98
-
127.0.0.1:6379> REDISQL.EXEC user "SELECT * FROM user;"
99
-
1) 1) "test@test.it"
100
-
2) "very secret"
101
-
2) 1) "noob@security.io"
102
-
2) "password"
103
-
127.0.0.1:6379>
104
-
105
-
```
106
-
107
-
### REDISQL.DELETE_DB key
108
-
109
-
This function will remove the database bound to `key`, for now the database will be completely lost after this operation.
110
-
111
-
This function is equivalent to `DELL key` however it won't let you delete keys that are not DBs.
112
-
113
-
```
114
-
127.0.0.1:6379> REDISQL.DELETE_DB user
115
-
OK
116
-
127.0.0.1:6379> REDISQL.EXEC user "SELECT * FROM user;"
117
-
(error) WRONGTYPE Operation against a key holding the wrong kind of value
118
-
```
119
-
120
74
## Walkthrough
121
75
122
-
123
76
After starting redis with the module rediSQL it will be just the redis you learn to love:
124
77
125
78
```
@@ -131,7 +84,7 @@ OK
131
84
"3"
132
85
```
133
86
134
-
But you will also able to use all the API described above
87
+
But you will also able to use all the API described below:
135
88
136
89
```
137
90
127.0.0.1:6379> REDISQL.CREATE_DB DB
@@ -201,36 +154,133 @@ OK
201
154
2) 1) "anana"
202
155
```
203
156
204
-
Errors are not yet well managed as they should be.
157
+
Now you can create tables, insert data on those tables, make queries, remove elements, everything.
205
158
159
+
## API
206
160
207
-
Now you can create tables, insert data on those tables, make queries, remove elements, everything.
161
+
### REDISQL.CREATE_DB key
208
162
209
-
Finally all the above features can be applied to the default DB or to a databases bound to a specif key.
163
+
This function will create a new SQLite database that will be bound to `key`.
210
164
211
-
## Benchmark
165
+
```
166
+
127.0.0.1:6379> REDISQL.CREATE_DB user
167
+
OK
168
+
```
212
169
213
-
Benchmarks are a little tricky, there are a lot of factor that may alter them, especially in this particular case.
170
+
### REDISQL.EXEC key statement
214
171
215
-
However just to have an idea of the order of magnitude of insert per second I wrote a [little test](https://github.com/RedBeardLab/rediSQL/blob/381e3796ad31c231719380afb92352c54b244b8c/test/performance/rediSQL_bench.py).
172
+
This command will execute the statement against the database bound to `key`.
216
173
217
-
On my machine I got 1000 insert (each one in its own transaction) in 0.6 seconds which let me claim 1000 / 0.6 => 1600 insert per second.
174
+
```
175
+
$ ./redis-cli
176
+
127.0.0.1:6379> REDISQL.CREATE_DB user
177
+
OK
218
178
219
-
I believe that there are A LOT of possibilities to improvements this numbers but I also thinks that they are good enough for most workload.
179
+
$ ./redis-cli
180
+
127.0.0.1:6379> REDISQL.EXEC user "CREATE TABLE user(email TEXT, password TEXT)"
181
+
OK
182
+
127.0.0.1:6379> REDISQL.EXEC user "INSERT INTO user VALUES('test@test.it','very secret')"
183
+
OK
184
+
127.0.0.1:6379> REDISQL.EXEC user "INSERT INTO user VALUES('noob@security.io', 'password')"
185
+
OK
186
+
127.0.0.1:6379> REDISQL.EXEC user "SELECT * FROM user;"
187
+
1) 1) "test@test.it"
188
+
2) "very secret"
189
+
2) 1) "noob@security.io"
190
+
2) "password"
191
+
127.0.0.1:6379>
192
+
193
+
```
194
+
195
+
## Benchmarks
196
+
197
+
Benchmarks are always tricky and it definitely depends on your use case, however I can provide some number at least for `INSERT` operations.
198
+
199
+
I ran a simple benchmark where I insert a tuple of 3 integers.
$ ./redis-benchmark -e -c 50 -n 500000 -r 100000 REDISQL.EXEC A "INSERT INTO test VALUES(__rand_int__,__rand_int__,__rand_int__);"
221
+
====== REDISQL.EXEC A INSERT INTO test VALUES(__rand_int__,__rand_int__,__rand_int__); ======
222
+
500000 requests completed in 10.44 seconds
223
+
50 parallel clients
224
+
3 bytes payload
225
+
keep alive: 1
226
+
227
+
84.19% <= 1 milliseconds
228
+
99.38% <= 2 milliseconds
229
+
99.92% <= 3 milliseconds
230
+
99.93% <= 9 milliseconds
231
+
99.94% <= 10 milliseconds
232
+
99.95% <= 11 milliseconds
233
+
99.95% <= 13 milliseconds
234
+
99.95% <= 14 milliseconds
235
+
99.96% <= 15 milliseconds
236
+
99.96% <= 78 milliseconds
237
+
99.96% <= 79 milliseconds
238
+
99.97% <= 80 milliseconds
239
+
99.97% <= 89 milliseconds
240
+
99.97% <= 90 milliseconds
241
+
99.98% <= 91 milliseconds
242
+
99.98% <= 94 milliseconds
243
+
99.98% <= 95 milliseconds
244
+
99.99% <= 96 milliseconds
245
+
99.99% <= 98 milliseconds
246
+
99.99% <= 99 milliseconds
247
+
100.00% <= 100 milliseconds
248
+
100.00% <= 101 milliseconds
249
+
100.00% <= 101 milliseconds
250
+
47915.67 requests per second
251
+
```
252
+
253
+
### Result
254
+
255
+
Overall Redis was able to manage ~70K PING per second and the module ~50K SQL inserts per seconds.
256
+
257
+
This is a very narrow test and if you care about performance, you should perform your own test; I would love if you could share your result.
258
+
259
+
Overall there are a lot of opportunity to optimize the SQL.
260
+
261
+
Also, keep in mind, that I am running those test in an old machine and your numbers may be different.
262
+
263
+
264
+
## Safeness vs. Performance
265
+
266
+
The tradeoff between safeness and performace is always crucial in all applications.
267
+
268
+
Since Redis is born as am in-memory database, as default, also the RediSQL modules works with in memory databases, however you can create a standard, file backed, database.
269
+
270
+
Also, you can adjust all the PRAGMA settings to fit your uses case.
220
271
221
-
If you need something faster, please take the time to open an issues and describe your use case.
222
272
223
273
## RoadMap
224
274
225
275
We would like to move following the necessity of the community, so ideas and use cases are extremely welcome.
226
276
227
277
We do have already a couple of ideas:
228
278
229
-
1. Introducing concurrency and non-blocking queries.
279
+
[x] Introducing concurrency and non-blocking queries.
230
280
231
-
2. Stream all the statements that modify the data, everything but `SELECT`s.
281
+
[] Supports for prepared statements
232
282
233
-
3. A cache system to store the result of the more complex select.
283
+
[] A cache system to store the result of the more complex select.
234
284
235
285
But please share your thoughts.
236
286
@@ -261,18 +311,17 @@ However when the dimension of the dataset start to approach a terabyte you may b
261
311
262
312
Of course if you use SQLite as in memory database the limiting factor will be the memory of your machine.
263
313
264
-
## Limit of the module
265
-
266
-
Right now there are some limit on the module implementation, these limitation are because my lack of time.
314
+
## Single thread
267
315
268
-
#### Single thread
316
+
When you create a new database a new thread is started, all the operations on the database will be performed by only that thread.
269
317
270
-
Right now the module use a single thread, the good news is that the thread is a different one that the Redis thread, this means that even during long operation your redis instance will be responsive.
318
+
The choice of using a single thread, in my tests, yielded overall better performaces.
271
319
320
+
Clearly, if the load is mainly reads, this choice will not be optimal.
272
321
273
322
## Alpha code
274
323
275
-
This is extremelly alpha code, there will be definitely some rough edges and some plain bugs.
324
+
This is alpha code, there will be definitely some rough edges and some plain bugs.
276
325
277
326
I really appreciate if you take your time to report those bugs.
0 commit comments