Discover Packages
github.com/cybersamx/go-recipes/redis/sessions
command
module
Version:
v0.0.0-...-838b099
Opens a new window with list of versions in this module.
Published: Oct 3, 2023
License: MIT
Opens a new window with license information.
Imports: 6
Opens a new window with list of imports.
Imported by: 0
Opens a new window with list of known importers.
README
README
¶
Expiring Sessions
Web sessions are ephemeral. We can leverage the EXPIRE
command in Redis to mark a key to be automatically removed from Redis when it expires. In this example, we explore how we can implement expiring web sessions in redis:
Use the Radix driver.
Use the Go-Redis driver.
Use GOB serialization to save complex types into Redis.
Setup
Start redis via docker compose:
$ docker-compose up
In the another shell, you can connect to Redis via the CLI tool:
$ docker-compose exec redis redis-cli
127.0.0.1:6379> KEYS sessions
Run Go program.
$ go run ./main.go
Shut down and remove the container when you are done.
$ # This should remove both redis-server and redis-cli
$ docker-compose down
Alternatively, you can run everything with just 2 commands.
$ make run
$ make teardown # Run this to remove the container
Reference and Credits
Expand ▾
Collapse ▴
Documentation
¶
There is no documentation for this package.
Source Files
¶
Directories
¶
Click to show internal directories.
Click to hide internal directories.