-
Notifications
You must be signed in to change notification settings - Fork 0
/
list.go
39 lines (31 loc) · 1.01 KB
/
list.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
package blocklist
import (
"github.com/redis/go-redis/v9"
"github.com/divergentcodes/jwt-block/internal/core"
)
// A ListResult contains the result of listing token hashes in the blocklist.
type ListResult struct {
TokenHashes []string `json:"token_hashes"` // hashes of blocked tokens.
Size int64 `json:"size"` // the number of blocked tokens.
IsError bool `json:"error"` // whether or not the result was an error.
}
// List will dump all token hashes in the cache.
func List(redisDB *redis.Client) (*ListResult, error) {
logger := core.GetLogger()
result := &ListResult{
Size: -1,
IsError: false,
}
size, err := Size(redisDB)
if err != nil {
result.IsError = true
return result, err
}
// Keys are the token hashes.
// Getting token hashes just requires calling "KEYS."
cacheKeys := redisDB.Keys(redisContext, "*")
result.TokenHashes = cacheKeys.Val()
result.Size = size
logger.Infow("Listed token hashes in the blocklist", "size", result.Size)
return result, nil
}