...

Source file src/github.com/gin-gonic/contrib/sessions/redis.go

Documentation: github.com/gin-gonic/contrib/sessions

     1  package sessions
     2  
     3  import (
     4  	"github.com/boj/redistore"
     5  	"github.com/gorilla/sessions"
     6  )
     7  
     8  type RedisStore interface {
     9  	Store
    10  }
    11  
    12  // size: maximum number of idle connections.
    13  // network: tcp or udp
    14  // address: host:port
    15  // password: redis-password
    16  // Keys are defined in pairs to allow key rotation, but the common case is to set a single
    17  // authentication key and optionally an encryption key.
    18  //
    19  // The first key in a pair is used for authentication and the second for encryption. The
    20  // encryption key can be set to nil or omitted in the last pair, but the authentication key
    21  // is required in all pairs.
    22  //
    23  // It is recommended to use an authentication key with 32 or 64 bytes. The encryption key,
    24  // if set, must be either 16, 24, or 32 bytes to select AES-128, AES-192, or AES-256 modes.
    25  func NewRedisStore(size int, network, address, password string, keyPairs ...[]byte) (RedisStore, error) {
    26  	store, err := redistore.NewRediStore(size, network, address, password, keyPairs...)
    27  	if err != nil {
    28  		return nil, err
    29  	}
    30  	return &redisStore{store}, nil
    31  }
    32  
    33  type redisStore struct {
    34  	*redistore.RediStore
    35  }
    36  
    37  func (c *redisStore) Options(options Options) {
    38  	c.RediStore.Options = &sessions.Options{
    39  		Path:     options.Path,
    40  		Domain:   options.Domain,
    41  		MaxAge:   options.MaxAge,
    42  		Secure:   options.Secure,
    43  		HttpOnly: options.HttpOnly,
    44  	}
    45  }
    46  

View as plain text