Add updated version of Redis modules
[ric-plt/dbaas.git] / redismodule / README.md
1 # Introduction
2
3 This subdirectory provides implementation for the commands which are implemented
4 as a [Redis modules](https://redis.io/topics/modules-intro).
5
6 # Compiling and UT (Unit Tests)
7
8 To compile and install run standard automake commands
9 in the redismodule directory:
10 ```
11 ./autogen.sh
12 ./configure
13 make
14 make install
15 ```
16
17 To run unit tests `cpputest` and `valgrind`
18 need to be installed as additional dependencies.
19 To enable and run unit tests use the commands:
20 ```
21 ./autogen.sh
22 ./configure --enable-unit-test
23 make test
24 ```
25
26 # Commands
27
28 ## SETIE key value oldvalue [expiration EX seconds|PX milliseconds]
29
30 Time complexity: O(1) + O(1)
31
32 Checks a String 'key' for 'oldvalue' equality and set key for 'value' with
33 optional expired.
34
35 ```
36 Example:
37
38 redis> get mykey
39 (nil)
40 redis> setie mykey "Hello again" "Hello"
41 (nil)
42
43 redis> set mykey "Hello"
44 OK
45 redis> get mykey
46 "Hello"
47 redis> setie mykey "Hello again" "Hello"
48 "OK"
49 redis> get mykey
50 "Hello again"
51 redis> setie mykey "Hello 2" "Hello"
52 (nil)
53 redis> get mykey
54 "Hello again"
55 redis> setie mykey "Hello 2" "Hello again" ex 100
56 "OK"
57 redis> ttl mykey
58 (integer) 96
59 redis> get mykey
60 "Hello 2"
61 ```
62
63 ## SETNE key value oldvalue [expiration EX seconds|PX milliseconds]
64
65 Time complexity: O(1) + O(1)
66
67 Checks a String 'key' for 'oldvalue' not equality and set key for 'value' with optional expired.
68
69 Example:
70
71 ```
72 redis> get mykey
73 (nil)
74 redis> setne mykey "Hello again" "Hello"
75 "OK"
76 redis> get mykey
77 "Hello again"
78 redis> setne mykey "Hello 2" "Hello again"
79 (nil)
80 redis> setne mykey "Hello 2" "Hello"
81 "OK"
82 redis> get mykey
83 "Hello 2"
84 redis> setne mykey "Hello 3" "Hello" ex 100
85 "OK"
86 redis> get mykey
87 "Hello 3"
88 redis> ttl mykey
89 (integer) 93
90 ```
91
92 ## DELIE key oldvalue
93
94 Time complexity: O(1) + O(1)
95
96 Checks a String 'key' for 'oldvalue' equality and delete the key.
97
98 ```
99 Example:
100 redis> get mykey
101 (nil)
102 redis> set mykey "Hello"
103 "OK"
104 redis> get mykey
105 "Hello"
106 redis> delie mykey "Hello again"
107 (integer) 0
108 redis> get mykey
109 "Hello"
110 redis> delie mykey "Hello"
111 (integer) 1
112 redis> get mykey
113 (nil)
114 ```
115
116 ## DELNE key oldvalue
117
118 Time complexity: O(1) + O(1)
119
120 Checks a String 'key' for 'oldvalue' not equality and delete the key.
121
122 ```
123 Example:
124 redis> get mykey
125 (nil)
126 redis> set mykey "Hello"
127 "OK"
128 redis> get mykey
129 "Hello"
130 redis> delne mykey "Hello"
131 (integer) 0
132 redis> get mykey
133 "Hello"
134 redis> delne mykey "Hello again"
135 (integer) 1
136 redis> get mykey
137 (nil)
138 ```
139
140 ## MSETPUB key value [key value...] channel message
141
142 Time complexity: O(N) where N is the number of keys to set + O(N+M) where N is the number of clients subscribed to the receiving channel and M is the total number of subscribed patterns (by any client)
143
144 Set the given keys to their respective values and post a message to the given channel
145
146 ## MSETMPUB number_of_key_value_pairs number_of_channel_message_pairs key value [ key value ... ] channel message [ channel message ... ]
147
148 Time complexity: O(N) where N is the number of keys to set + O(N_1+M) [ + O(N_2+M) + ... ] where N_i are the number of clients subscribed to the corresponding receiving channel and M is the total number of subscribed patterns (by any client)
149
150 Set the given keys to their respective values and post messages to their respective channels
151
152 ## SETXXPUB key value channel message [channel message...]
153
154 Time complexity: O(1) + O(1) + O(N_1+M) [ + O(N_2+M) + ... ] where N_i are the number of clients subscribed to the receiving channel and M is the total number of subscribed patterns (by any client).
155
156 Set key to hold string value if key already exists and post given messages to the corresponding channels if key value was set successfully
157
158 ## SETNXPUB key value channel message [channel message...]
159
160 Time complexity: O(1) + O(1) + O(N_1+M) [ + O(N_2+M) + ... ] where N_i are the number of clients subscribed to the receiving channel and M is the total number of subscribed patterns (by any client).
161
162 Set key to hold string value if key does not exist and post given messages to the corresponding channels if key value was set successfully
163
164 ## SETIEPUB key value oldvalue channel message [channel message...]
165
166 Time complexity: O(1) + O(1) + O(1) + O(N_1+M) [ + O(N_2+M) + ... ] where N_i are the number of clients subscribed to the receiving channel and M is the total number of subscribed patterns (by any client).
167
168 If the string corresponding to 'key' is equal to 'oldvalue' then set key for 'value' and post given messages to the corresponding channels if key value was set successfully
169
170 ## SETNEPUB key value oldvalue channel message [channel message...]
171
172 Time complexity: O(1) + O(1) + O(1) + O(N_1+M) [ + O(N_2+M) + ... ] where N_i are the number of clients subscribed to the receiving channel and M is the total number of subscribed patterns (by any client).
173
174 If the string corresponding to 'key' is not equal to 'oldvalue' then set key for 'value' and post given messages to the corresponding channels if key value was set successfully
175
176 ## DELPUB key [key...] channel message
177
178 Time complexity: O(N) where N is the number of keys that will be removed + O(N+M) where N is the number of clients subscribed to the receiving channel and M is the total number of subscribed patterns (by any client)
179
180 Removes the specified keys and post a message to the given channel if delete key successfully(return >0)
181
182 ## DELMPUB number_of_keys number_of_channel_message_pairs key [ key ... ] channel message [ channel message ... ]
183
184 Time complexity: O(N) where N is the number of keys that will be removed + O(N_1+M) [ + O(N_2+M) + ... ] where N_i are the number of clients subscribed to the receiving channel and M is the total number of subscribed patterns (by any client)
185
186 Remove the specified keys. If any of the keys was deleted succesfully (delete return value > 0) then post given messages to the corresponding channels.
187
188 ## DELIEPUB key oldvalue channel message [channel message...]
189
190 Time complexity: O(1) + O(1) + O(1) + O(N_1+M) [ + O(N_2+M) + ...] where N_i are the number of clients subscribed to the corrensponding receiving channel and M is the total number of subscribed patterns (by any client)
191
192 If the string corresponding to 'key' is equal to 'oldvalue' then delete the key. If deletion was succesful (delete return value was 1) then post given messages to the corresponding channels.
193
194 ## DELNEPUB key oldvalue channel message [channel message...]
195
196 Time complexity: O(1) + O(1) + O(1) + O(N_1+M) [ + O(N_2+M) + ...] where N_i are the number of clients subscribed to the corrensponding receiving channel and M is the total number of subscribed patterns (by any client)
197
198 If the string corresponding to 'key' is not equal to 'oldvalue' then delete the key. If deletion was succesful (delete return value was 1) then post given messages to the corresponding channels.
199
200 ## NGET pattern
201
202 Time complexity: O(N) with N being the number of keys in the instance + O(N) where N is the number of keys to retrieve
203
204 Returns all key-value pairs matching pattern.
205
206 ```
207 example:
208
209 redis> nget mykey*
210 (empty list or set)
211
212 redis> set mykey1 "myvalue1"
213 OK
214 redis> set mykey2 "myvalue2"
215 OK
216 redis> set mykey3 "myvalue3"
217 OK
218 redis> set mykey4 "myvalue4"
219 OK
220 redis> nget mykey*
221 1) "mykey2"
222 2) "myvalue2"
223 3) "mykey1"
224 4) "myvalue1"
225 5) "mykey4"
226 6) "myvalue4"
227 7) "mykey3"
228 8) "myvalue3"
229 ```
230
231 ## NDEL pattern
232
233 Time complexity: O(N) with N being the number of keys in the instance + O(N) where N is the number of keys that will be removed
234
235 Remove all key-value pairs matching pattern.
236
237 ```
238 example:
239
240 redis> nget mykey*
241 1) "mykey2"
242 2) "myvalue2"
243 3) "mykey1"
244 4) "myvalue1"
245 5) "mykey4"
246 6) "myvalue4"
247 7) "mykey3"
248 8) "myvalue3"
249
250 redis> ndel mykey*
251 (integer) 4
252
253 redis> ndel mykey*
254 (integer) 0
255 ```