Skip to content

Using redis

Fabian Wenzelmann edited this page Apr 3, 2017 · 5 revisions

Using redis

New in version v0.3

redis is a very popular storage system. Since version v0.3 there is support for redis session and user backend.

Quickstart Example

...
import "github.com/go-redis/redis"

client := redis.NewClient(&redis.Options{
		Addr:     "localhost:6379",
		Password: "", // no password set
		DB:       0,  // use default DB
})
redisHandler := goauth.NewRedisSessionHandler(client)
controller := goauth.NewSessionController(redisHandler)

Then use it as you're used to. You should read the doc first however.

When you're using redis you don't need take care to delete invalid keys, redis will do this for you already. If you use a different type than uint64 as your key type for users you should define a different ConvertUser function.

To manage users simply do

...
import "github.com/go-redis/redis"

client := redis.NewClient(&redis.Options{
		Addr:     "localhost:6379",
		Password: "", // no password set
		DB:       0,  // use default DB
})
h := goauth.NewRedisUserHandler(client, nil)

Read the docs:

Clone this wiki locally