kemal-session-redis~crystal-garage

Redis store for kemal-session kemal session session-storage-engine
0.6.1 Latest release released

kemal-session-redis

Crystal CI

Redis session store for kemal-session.

Installation

Add this to your application's shard.yml:

dependencies:
  kemal-session-redis:
    github: mamantoha/kemal-session-redis
    branch: develop

Usage

require "kemal"
require "kemal-session"
require "kemal-session-redis"

Kemal::Session.config do |config|
  config.cookie_name = "redis_test"
  config.secret = "a_secret"
  config.engine = Kemal::Session::RedisEngine.new(host: "localhost", port: 1234)
  config.timeout = 1.day
end

get "/" do
  puts "Hello World"
end

post "/sign_in" do |context|
  context.session.int("see-it-works", 1)
end

Kemal.run

The engine comes with a number of configuration options:

| Option | Description | | ------ | ----------- | | host | where your redis instance lives | | port | assigned port for redis instance | | unixsocket | Use a socket instead of host/port. This will override host / port settings | | database | which database to use when after connecting to redis. defaults to 0 | | pool_size | how many connections the connection pool should create. defaults to 5 | | pool_timeout | how long until a connection is considered long-running. defaults to 2.0 (seconds) | | key_prefix | when saving sessions to redis, how should the keys be namespaced. defaults to kemal:session: |

When the Redis engine is instantiated and a connection pool isn't passed, RedisEngine will create a connection pool for you. The pool will have 5 connections and a timeout of 2 seconds.

Best Practices

Session Administration Performance

Kemal::Session.all and Kemal::Session.each perform a bit differently under the hood. If Kemal::Session.all is used, the RedisEngine will use the SCAN command in Redis and page through all of the sessions, hydrating the Session object and returing an array of all sessions. If session storage has a large number of sessions this could have performance implications. Kemal::Session.each also uses the SCAN command in Redis but instead of creating one large array and enumerating through it, Kemal::Session.each will only hydrate and yield the keys returned from the current cursor. Once that block of sessions has been yielded, RedisEngine will retrieve the next block of sessions.

Development

Redis must be running on localhost and bound to the default port to run specs.

Contributing

  1. Fork it (https://github.com/mamantoha/kemal-session-redis/fork)
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create a new Pull Request

Contributors

kemal-session-redis:
  github: crystal-garage/kemal-session-redis
  version: ~> 0.6.1
License MIT
Crystal >= 1.0.0

Authors

Dependencies 2

  • kemal-session ~> 1.0.0
    {'github' => 'kemalcr/kemal-session', 'version' => '~> 1.0.0'}
  • redis >= 2.7.0
    {'github' => 'stefanwille/crystal-redis', 'version' => '>= 2.7.0'}

Development Dependencies 0

Dependents 1

Last synced .
search fire star recently