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