Documentation
¶
Overview ¶
Package redis provides an io/fs.FS implementation that can be used in our cache.FS package.
Here's an example that simply accesses a local Redis instance:
redisFS, err := redis.New( redis.Args{Addr: "127.0.0.1:6379"}, // This causes all files to exire in 5 minutes. // You can write a complex ruleset to handle different files at // different rates. redis.WithWriteFileOFOptions( regexp.MustCompile(`.*`), redis.ExpireFiles(5 * time.Minute), ), ) if err != nil { // Do something } if err := redisFS.WriteFile("gopher.jpg", gopherBytes, 0644); err != nil { // Do something }
Index ¶
- func ExpireFiles(d time.Duration) jsfs.OFOption
- func Flags(flags int) jsfs.OFOption
- type Args
- type FS
- func (f *FS) Open(name string) (fs.File, error)
- func (f *FS) OpenFile(name string, mode fs.FileMode, options ...jsfs.OFOption) (fs.File, error)
- func (f *FS) ReadFile(name string) ([]byte, error)
- func (f *FS) Remove(name string) error
- func (f *FS) Stat(name string) (fs.FileInfo, error)
- func (f *FS) WriteFile(name string, content []byte, perm fs.FileMode) error
- type Option
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ExpireFiles ¶
ExpireFiles expires files at duration d. If not set for a file, redis.KeepTTL is used.
Types ¶
type FS ¶
type FS struct {
// contains filtered or unexported fields
}
FS provides an io.FS implementation using Redis.
func (*FS) OpenFile ¶
OpenFile implements fs.OpenFiler.OpenFile(). We support os.O_CREATE, os.O_EXCL, os.O_RDONLY, os.O_WRONLY, and os.O_TRUNC. If OpenFile is passed O_RDONLY, this calls Open() and ignores all options. When writing a file, the file is not written until Close() is called on the file.
func (*FS) Stat ¶
Stat implements fs.StatFS.Stat(). The FileInfo returned name and size can be used, but the others are static values. ModTime will always be the zero value. It should be noted that this is simple a bad wrapper on Open(), so the content is read as I did not see a way to query Redis for just the key size (and to be honest, I didn't dig to hard).
type Option ¶
Option is an optional argument for the New() constructor.
func WithWriteFileOFOptions ¶
WithWriteFileOFOption uses a regex on the file path given and if it matches will apply the options provided on that file when .WriteFile() is called. First match wins. A "nil" for a regex applies to all that are not matched. It is suggested for speed reasons to keep this relatively small or the first rules should match the majority of files. This can be passed multiple times with different regexes.