Module retrieves or initializes a new module-specific Storage instance.
(name string)
| 16 | |
| 17 | // Module retrieves or initializes a new module-specific Storage instance. |
| 18 | func (s *ModuleStorage) Module(name string) (storage.Storer, error) { |
| 19 | |
| 20 | // Check if the module exists in Redis. |
| 21 | exists, err := s.client.SIsMember(ctx, withNamespace(s.namespacePrefix, modulePrefix, ""), name).Result() |
| 22 | if err != nil { |
| 23 | return nil, err |
| 24 | } |
| 25 | |
| 26 | if !exists { |
| 27 | // If the module does not exist, add it to the set of modules. |
| 28 | err = s.client.SAdd(ctx, withNamespace(s.namespacePrefix, modulePrefix, ""), name).Err() |
| 29 | if err != nil { |
| 30 | return nil, err |
| 31 | } |
| 32 | } |
| 33 | |
| 34 | // Initialize a new Storage instance for the module. |
| 35 | // The module-specific namespace or prefix can be used for module-specific data. |
| 36 | moduleStorage := NewStorage(s.client.Options(), withNamespace(s.namespacePrefix, modulePrefix, "")) |
| 37 | |
| 38 | return moduleStorage, nil |
| 39 | } |
nothing calls this directly
no test coverage detected