sessionredis

package module
v0.0.0-...-a226021 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 8, 2022 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

Package sessionbolt provides a Redis store for sessions.

This package is only compatible with https://github.com/go-redis/redis. But since this package has several different versions for different versions of Redis, we do not import any of them, but ensure compatibility with any of them through generics.

How to use?

  1. go get and import relavant go-redis module
  2. go get and import this module
  3. define store

Example:

 import (
   "github.com/go-redis/redis/v9"
   // or "github.com/go-redis/redis/v8"
   "github.com/mr-linch/go-tg/tgb/session/sessionredis"
 )

 func run(ctx context.Context) error {
	  opts, err := redis.ParseURL("redis://localhost:6379")
   if err != nil {
     return err
   }
   client := redis.NewClient(opts)

   store := sessionredis.NewStore[*redis.StatusCmd, *redis.StringCmd, *redis.IntCmd](client)
   // use store :)
 }

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Redis

type Redis[
	SR redisStatusCmd,
	GR redisStringCmd,
	DR redisIntCmd,
] interface {
	Set(ctx context.Context, key string, value interface{}, exp time.Duration) SR
	Get(ctx context.Context, key string) GR
	Del(ctx context.Context, keys ...string) DR
}

type Store

type Store[
	SR redisStatusCmd,
	GR redisStringCmd,
	DR redisIntCmd,
] struct {
	// contains filtered or unexported fields
}

func NewStore

func NewStore[
	SR redisStatusCmd,
	GR redisStringCmd,
	DR redisIntCmd,
](redis Redis[SR, GR, DR]) *Store[SR, GR, DR]

func (*Store[SR, GR, DR]) Del

func (s *Store[SR, GR, DR]) Del(ctx context.Context, key string) error

func (*Store[SR, GR, DR]) Get

func (s *Store[SR, GR, DR]) Get(ctx context.Context, key string) ([]byte, error)

func (*Store[SR, GR, DR]) Set

func (s *Store[SR, GR, DR]) Set(ctx context.Context, key string, value []byte) error

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL