17
17
}
18
18
location /start {
19
19
content_by_lua '
20
- local session = require "resty.session".start()
20
+ local session = require( "resty.session") .start()
21
21
session.data.name = "OpenResty Fan"
22
22
session:save()
23
23
ngx.say("<html><body>Session started. ",
@@ -26,24 +26,25 @@ http {
26
26
}
27
27
location /test {
28
28
content_by_lua '
29
- local session = require "resty.session".start()
29
+ local session = require( "resty.session") .start()
30
30
ngx.say("<html><body>Session was started by <strong>",
31
31
session.data.name or "Anonymous",
32
32
"</strong>! <a href=/destroy>Destroy the session</a>.</body></html>")
33
33
';
34
34
}
35
35
location /destroy {
36
36
content_by_lua '
37
- local session = require "resty.session".start()
37
+ local session = require( "resty.session") .start()
38
38
session:destroy()
39
39
ngx.say("<html><body>Session was destroyed. ",
40
40
"<a href=/check>Is it really so</a>?</body></html>")
41
41
';
42
42
}
43
43
location /check {
44
44
content_by_lua '
45
- local session = require "resty.session".start()
46
- ngx.say("<html><body>Session was really destroyed, you are known as <strong>",
45
+ local session = require("resty.session").start()
46
+ ngx.say("<html><body>Session was really destroyed, you are known as ",
47
+ "<strong>",
47
48
session.data.name or "Anonymous",
48
49
"</strong>! <a href=/>Start again</a>.</body></html>")
49
50
';
@@ -127,9 +128,9 @@ does also manage session cookie renewing configured with `$session_cookie_renew`
127
128
with a new expiration time if the following is met ` session.expires - now < session.cookie.renew ` .
128
129
129
130
``` lua
130
- local session = require " resty.session" .start ()
131
+ local session = require ( " resty.session" ) .start ()
131
132
-- Set some options (overwriting the defaults or nginx configuration variables)
132
- local session = require " resty.session" .start { identifier = { length = 32 }}
133
+ local session = require ( " resty.session" ) .start { identifier = { length = 32 }}
133
134
```
134
135
135
136
#### boolean session: regenerate (flush or nil)
@@ -143,7 +144,7 @@ actually happens when the cookie's expiration time is not valid anymore). This f
143
144
value if everything went as planned (you may assume that it is always the case).
144
145
145
146
``` lua
146
- local session = require " resty.session" .start ()
147
+ local session = require ( " resty.session" ) .start ()
147
148
session :regenerate ()
148
149
-- Flush the current data
149
150
session :regenerate (true )
@@ -157,7 +158,7 @@ advised that you call this function only once per request (no need to encrypt an
157
158
This function returns a boolean value if everything went as planned (you may assume that it is always the case).
158
159
159
160
``` lua
160
- local session = require " resty.session" .start ()
161
+ local session = require ( " resty.session" ) .start ()
161
162
session .data .uid = 1
162
163
session :save ()
163
164
```
@@ -170,7 +171,7 @@ should remove the cookie, and not send it back again). This function returns a b
170
171
as planned (you may assume that it is always the case).
171
172
172
173
``` lua
173
- local session = require " resty.session" .start ()
174
+ local session = require ( " resty.session" ) .start ()
174
175
session :destroy ()
175
176
```
176
177
@@ -201,15 +202,15 @@ you need to call `session:save` method.
201
202
** Setting session variable:**
202
203
203
204
``` lua
204
- local session = require " resty.session" .start ()
205
+ local session = require ( " resty.session" ) .start ()
205
206
session .data .uid = 1
206
207
session :save ()
207
208
```
208
209
209
210
** Retrieving session variable (in other request):**
210
211
211
212
``` lua
212
- local session = require " resty.session" .start ()
213
+ local session = require ( " resty.session" ) .start ()
213
214
local uid = session .data .uid
214
215
```
215
216
0 commit comments