Refactor setpub-commands, Allow multiple channels
[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 # Commands
7
8 ## SETIE key value oldvalue [expiration EX seconds|PX milliseconds]
9
10 Time complexity: O(1) + O(1)
11
12 Checks a String 'key' for 'oldvalue' equality and set key for 'value' with
13 optional expired.
14
15 ```
16 Example:
17
18 redis> get mykey
19 (nil)
20 redis> setie mykey "Hello again" "Hello"
21 (nil)
22
23 redis> set mykey "Hello"
24 OK
25 redis> get mykey
26 "Hello"
27 redis> setie mykey "Hello again" "Hello"
28 "OK"
29 redis> get mykey
30 "Hello again"
31 redis> setie mykey "Hello 2" "Hello"
32 (nil)
33 redis> get mykey
34 "Hello again"
35 redis> setie mykey "Hello 2" "Hello again" ex 100
36 "OK"
37 redis> ttl mykey
38 (integer) 96
39 redis> get mykey
40 "Hello 2"
41 ```
42
43 ## SETNE key value oldvalue [expiration EX seconds|PX milliseconds]
44
45 Time complexity: O(1) + O(1)
46
47 Checks a String 'key' for 'oldvalue' not equality and set key for 'value' with optional expired.
48
49 Example:
50
51 ```
52 redis> get mykey
53 (nil)
54 redis> setne mykey "Hello again" "Hello"
55 "OK"
56 redis> get mykey
57 "Hello again"
58 redis> setne mykey "Hello 2" "Hello again"
59 (nil)
60 redis> setne mykey "Hello 2" "Hello"
61 "OK"
62 redis> get mykey
63 "Hello 2"
64 redis> setne mykey "Hello 3" "Hello" ex 100
65 "OK"
66 redis> get mykey
67 "Hello 3"
68 redis> ttl mykey
69 (integer) 93
70 ```
71
72 ## DELIE key oldvalue
73
74 Time complexity: O(1) + O(1)
75
76 Checks a String 'key' for 'oldvalue' equality and delete the key.
77
78 ```
79 Example:
80 redis> get mykey
81 (nil)
82 redis> set mykey "Hello"
83 "OK"
84 redis> get mykey
85 "Hello"
86 redis> delie mykey "Hello again"
87 (integer) 0
88 redis> get mykey
89 "Hello"
90 redis> delie mykey "Hello"
91 (integer) 1
92 redis> get mykey
93 (nil)
94 ```
95
96 ## DELNE key oldvalue
97
98 Time complexity: O(1) + O(1)
99
100 Checks a String 'key' for 'oldvalue' not equality and delete the key.
101
102 ```
103 Example:
104 redis> get mykey
105 (nil)
106 redis> set mykey "Hello"
107 "OK"
108 redis> get mykey
109 "Hello"
110 redis> delne mykey "Hello"
111 (integer) 0
112 redis> get mykey
113 "Hello"
114 redis> delne mykey "Hello again"
115 (integer) 1
116 redis> get mykey
117 (nil)
118 ```
119
120 ## MSETPUB key value [key value...] channel message
121
122 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)
123
124 Set the given keys to their respective values and post a message to the given channel
125
126 ## SETXXPUB key value channel message [channel message...]
127
128 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).
129
130 Set key to hold string value if key already exists and post given messages to the corresponding channels if key value was set successfully
131
132 ## SETNXPUB key value channel message [channel message...]
133
134 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).
135
136 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
137
138 ## SETIEPUB key value oldvalue channel message [channel message...]
139
140 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).
141
142 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
143
144 ## SETNEPUB key value oldvalue channel message [channel message...]
145
146 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).
147
148 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
149
150 ## DELPUB key [key...] channel message
151
152 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)
153
154 Removes the specified keys and post a message to the given channel if delete key successfully(return >0)
155
156 ## DELIEPUB key oldvalue channel message
157
158 ime complexity: O(1) + O(1) + O(1) + 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)
159
160 Checks a String 'key' for 'oldvalue' equality and delete the key and post a message to the given channel if delete key successfully(return 1)
161
162 ## DELNEPUB key oldvalue channel message
163
164 Time complexity: O(1) + O(1) + O(1) + 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)
165
166 Checks a String 'key' for 'oldvalue' not equality and delete the key and post a message to the given channel if delete key successfully(return 1)
167
168 ## NGET pattern
169
170 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
171
172 Returns all key-value pairs matching pattern.
173
174 ```
175 example:
176
177 redis> nget mykey*
178 (empty list or set)
179
180 redis> set mykey1 "myvalue1"
181 OK
182 redis> set mykey2 "myvalue2"
183 OK
184 redis> set mykey3 "myvalue3"
185 OK
186 redis> set mykey4 "myvalue4"
187 OK
188 redis> nget mykey*
189 1) "mykey2"
190 2) "myvalue2"
191 3) "mykey1"
192 4) "myvalue1"
193 5) "mykey4"
194 6) "myvalue4"
195 7) "mykey3"
196 8) "myvalue3"
197 ```
198
199 ## NDEL pattern
200
201 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
202
203 Remove all key-value pairs matching pattern.
204
205 ```
206 example:
207
208 redis> nget mykey*
209 1) "mykey2"
210 2) "myvalue2"
211 3) "mykey1"
212 4) "myvalue1"
213 5) "mykey4"
214 6) "myvalue4"
215 7) "mykey3"
216 8) "myvalue3"
217
218 redis> ndel mykey*
219 (integer) 4
220
221 redis> ndel mykey*
222 (integer) 0
223 ```