GithubHelp home page GithubHelp logo

bizlaunchequity / plug_session_redis Goto Github PK

View Code? Open in Web Editor NEW

This project forked from aposto/plug_session_redis

0.0 4.0 0.0 16 KB

Session store in Redis for Elixir's plug

License: MIT License

Elixir 100.00%

plug_session_redis's Introduction

PlugSessionRedis

hex.pm version

The Redis Plug.Session adapter for the Phoenix framework. Poolboy + Redis.

Usage

# mix.exs
def application do
  [applications: [..., :plug_session_redis]]
end

defp deps do
  [{:plug_session_redis, "~> 0.1" }]
end

config.exs

config :plug_session_redis, :config,
  name: :redis_sessions,    # Can be anything you want, should be the same as `:table` config below
  pool: [size: 2, max_overflow: 5],
  redis: [host: '127.0.0.1', port: 6379]

endpoint.ex

plug Plug.Session,
  store: PlugSessionRedis.Store,
  key: "_my_app_key",           #
  table: :redis_sessions,       # Can be anything you want, should be same as `:name` config above
  signing_salt: "123456",       #
  encryption_salt: "654321",    #
  ttl: 360,                     # use redis EXPIRE secs
  serializer: CustomSerializer, # Optional, defaults to `PlugSessionRedis.BinaryEncoder`
  db_path: &MyPath.path/1          # Optional, defaults to passing the session ID through unmodified

Custom Serializers

Change the above serializer to your own implementation that has an encode/1, decode/1, encode!/1 and decode!/1 functions.

An example serializer is shown in lib/plug_session_redis/binary_encoder.ex. For data serialized by Ruby, you can use ex_marshal.

Storing data in another key

The :db_path option above when configuring the plug lets you define a function which will take in the session ID binary string and returns a new storage location. If you'd like, for example, to store all sessions under the key "myapp:sessions:" <> id then an example implementation of the above configured MyPath.path/1 would look like this:

defmodule MyPath do
  def path(sid) do
    "myapp:sessions:" <> sid
  end
end

NOTE: Plug does not allow passing in an anonymous function, it will have to be a named function as shown above.

plug_session_redis's People

Contributors

aposto avatar evilzorge avatar mgwidmann avatar oleghaidul avatar

Watchers

 avatar  avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.