Skip to content

Commit 4539f83

Browse files
committed
add type aliases for ngx.shared.DICT values
1 parent a427405 commit 4539f83

File tree

1 file changed

+27
-16
lines changed

1 file changed

+27
-16
lines changed

meta/3rd/OpenResty/library/ngx.lua

Lines changed: 27 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1255,6 +1255,13 @@ ngx.shared = {}
12551255
---@class ngx.shared.DICT
12561256
local DICT = {}
12571257

1258+
--- Valid values for ngx.shared.DICT
1259+
---@alias ngx.shared.DICT.value
1260+
---| string
1261+
---| number
1262+
---| boolean
1263+
---| nil
1264+
12581265
--- Retrieve a value. If the key does not exist or has expired, then `nil` will be returned.
12591266
---
12601267
--- In case of errors, `nil` and a string describing the error will be returned.
@@ -1269,7 +1276,7 @@ local DICT = {}
12691276
--- If the user flags is `0` (the default), then no flags value will be returned.
12701277
---
12711278
---@param key string
1272-
---@return any?
1279+
---@return ngx.shared.DICT.value? value
12731280
---@return ngx.shared.DICT.flags?|string? flags_or_error
12741281
function DICT:get(key) end
12751282

@@ -1281,7 +1288,7 @@ function DICT:get(key) end
12811288
--- Note that the value of an expired key is not guaranteed to be available so one should never rely on the availability of expired items.
12821289
---
12831290
---@param key string
1284-
---@return any? value
1291+
---@return ngx.shared.DICT.value? value
12851292
---@return ngx.shared.DICT.flags|string flags_or_error
12861293
---@return boolean stale
12871294
function DICT:get_stale(key) end
@@ -1320,7 +1327,7 @@ function DICT:get_stale(key) end
13201327
--- Please note that while internally the key-value pair is set atomically, the atomicity does not go across the method call boundary.
13211328
---
13221329
---@param key string
1323-
---@param value any
1330+
---@param value ngx.shared.DICT.value
13241331
---@param exptime? ngx.shared.DICT.exptime
13251332
---@param flags? ngx.shared.DICT.flags
13261333
---@return boolean ok # whether the key-value pair is stored or not
@@ -1331,7 +1338,7 @@ function DICT:set(key, value, exptime, flags) end
13311338
--- Similar to the `set` method, but never overrides the (least recently used) unexpired items in the store when running out of storage in the shared memory zone. In this case, it will immediately return `nil` and the string "no memory".
13321339
---
13331340
---@param key string
1334-
---@param value any
1341+
---@param value ngx.shared.DICT.value
13351342
---@param exptime? ngx.shared.DICT.exptime
13361343
---@param flags? ngx.shared.DICT.flags
13371344
---@return boolean ok # whether the key-value pair is stored or not
@@ -1344,7 +1351,7 @@ function DICT:safe_set(key, value, exptime, flags) end
13441351
--- If the `key` argument already exists in the dictionary (and not expired for sure), the `success` return value will be `false` and the `err` return value will be `"exists"`.
13451352
---
13461353
---@param key string
1347-
---@param value any
1354+
---@param value ngx.shared.DICT.value
13481355
---@param exptime? ngx.shared.DICT.exptime
13491356
---@param flags? ngx.shared.DICT.flags
13501357
---@return boolean ok # whether the key-value pair is stored or not
@@ -1355,7 +1362,7 @@ function DICT:add(key, value, exptime, flags) end
13551362
--- Similar to the `add` method, but never overrides the (least recently used) unexpired items in the store when running out of storage in the shared memory zone. In this case, it will immediately return `nil` and the string "no memory".
13561363
---
13571364
---@param key string
1358-
---@param value any
1365+
---@param value ngx.shared.DICT.value
13591366
---@param exptime? ngx.shared.DICT.exptime
13601367
---@param flags? ngx.shared.DICT.flags
13611368
---@return boolean ok # whether the key-value pair is stored or not
@@ -1369,7 +1376,7 @@ function DICT:safe_add(key, value, exptime, flags) end
13691376
--- If the `key` argument does *not* exist in the dictionary (or expired already), the `success` return value will be `false` and the `err` return value will be `"not found"`.
13701377
---
13711378
---@param key string
1372-
---@param value any
1379+
---@param value ngx.shared.DICT.value
13731380
---@param exptime? ngx.shared.DICT.exptime
13741381
---@param flags? ngx.shared.DICT.flags
13751382
---@return boolean ok # whether the key-value pair is stored or not
@@ -1417,15 +1424,19 @@ function DICT:delete(key) end
14171424
--- The `value` argument and `init` argument can be any valid Lua numbers, like negative numbers or floating-point numbers.
14181425
---
14191426
---
1420-
---@param key string
1421-
---@param value number
1422-
---@param init number
1423-
---@param init_ttl ngx.shared.DICT.exptime
1427+
---@param key string
1428+
---@param value number
1429+
---@param init? number
1430+
---@param init_ttl? ngx.shared.DICT.exptime
14241431
---@return integer? new
14251432
---@return ngx.shared.DICT.error? error
14261433
---@return boolean forcible
14271434
function DICT:incr(key, value, init, init_ttl) end
14281435

1436+
--- Valid ngx.shared.DICT value for lists
1437+
---@alias ngx.shared.DICT.list_value
1438+
---| string
1439+
---| number
14291440

14301441
--- Inserts the specified (numerical or string) `value` at the head of the list named `key`.
14311442
---
@@ -1434,16 +1445,16 @@ function DICT:incr(key, value, init, init_ttl) end
14341445
--- It never overrides the (least recently used) unexpired items in the store when running out of storage in the shared memory zone. In this case, it will immediately return `nil` and the string "no memory".
14351446
---
14361447
---@param key string
1437-
---@param value any
1448+
---@param value ngx.shared.DICT.list_value
14381449
---@return number? len # number of elements in the list after the push operation
14391450
---@return ngx.shared.DICT.error? error
1440-
function DICT:lpush(key,value) end
1451+
function DICT:lpush(key, value) end
14411452

14421453

14431454
--- Similar to the `lpush` method, but inserts the specified (numerical or string) `value` at the tail of the list named `key`.
14441455
---
14451456
---@param key string
1446-
---@param value any
1457+
---@param value ngx.shared.DICT.list_value
14471458
---@return number? len # number of elements in the list after the push operation
14481459
---@return ngx.shared.DICT.error? error
14491460
function DICT:rpush(key, value) end
@@ -1454,7 +1465,7 @@ function DICT:rpush(key, value) end
14541465
--- If `key` does not exist, it will return `nil`. When the `key` already takes a value that is not a list, it will return `nil` and `"value not a list"`.
14551466
---
14561467
---@param key string
1457-
---@return any? value
1468+
---@return ngx.shared.DICT.list_value? item
14581469
---@return ngx.shared.DICT.error? error
14591470
function DICT:lpop(key) end
14601471

@@ -1464,7 +1475,7 @@ function DICT:lpop(key) end
14641475
--- If `key` does not exist, it will return `nil`. When the `key` already takes a value that is not a list, it will return `nil` and `"value not a list"`.
14651476
---
14661477
---@param key string
1467-
---@return any? value
1478+
---@return ngx.shared.DICT.list_value? item
14681479
---@return ngx.shared.DICT.error? error
14691480
function DICT:rpop(key) end
14701481

0 commit comments

Comments
 (0)