Coder Social home page Coder Social logo

f0rmiga / sessiongate Goto Github PK

View Code? Open in Web Editor NEW
53.0 7.0 4.0 89 KB

⚡️A Redis module that provides session management.

License: MIT License

C 53.23% Python 12.78% Dockerfile 0.83% Shell 3.29% Go 29.87%
session session-management session-store sessions session-manager sessionstorage sessionmanager sessionstore redis redis-module

sessiongate's Introduction

CircleCI

FOSSA Status

Session Gate

Session Gate is a Redis module to ease session management using tokens. This module does NOT do user management, don't get confused. In the real world, most of the sessions are related to a user but do your crazy logic to manage the users the way you want.

How it works

This module provides creation and administration of sessions using tokens. Each session can have more than one payload and those payloads can be accessed individually. A single instance of Redis loaded with this module can handle sessions from multiple applications.

Redis is a high performance, in-memory data structure store. This module is built on top of it, meaning this module operates in a very similar way Redis itself operates.

To access this module, any Redis compatible driver can be used. The commands to operate this module are exposed like any other Redis command.

To know more about Redis modules, follow this link.

How to build

The module is written in C and uses Bazel to build. Bazel manages all the dependencies. :D

The dependencies are:

Building on Linux/OS X

Run:

bazel build //:sessiongate.so

Building on Windows

¯\_(ツ)_/¯

Building the Docker image

On Linux, Docker is necessary only if you want to load the built image into the daemon (which is almost always the case). On OS X and Windows, Docker is always required to be installed.

On Linux, simply run bazel run //:sessiongate_image. It will build and load the image.

On OS X and Windows, run the script ./build_and_load_image_with_docker.sh, which uses Docker in Docker for building the module and appending it as a layer on top of the Redis image.

How to run tests

Tests are located under tests/ directory and are written in Python. You should have Python 2.7+ installed in order to run the tests. Run:

bazel test //...

For verbose tests run:

bazel test --test_output=all //...

Loading the module for use

The module can be loaded in Redis 4+. The most convenient way to do that is by passing --loadmodule parameter when starting the Redis server:

redis-server --loadmodule <path_to_sessiongate.so>

For example, starting Redis open to the world and the Session Gate loaded:

redis-server --protected-mode no --loadmodule $(pwd)/bazel-bin/sessiongate.so

Just make sure to pass the right sessiongate.so path value to the --loadmodule parameter.

Commands

Start a session

Command: SESSIONGATE.START <sign_key> <ttl>

  • <sign_key> is the secret string used by the HMAC algorithm to generate the token signature.
  • <ttl> is the positive integer that represents the seconds that the session will live. If set to 0, the session expires immediately.

Example

SESSIONGATE.START 'qwerty' 300

Returns: a token that is used to manage the session.

Set a session TTL

Command: SESSIONGATE.EXPIRE <sign_key> <token> <ttl>

  • <sign_key> is the secret string used by the HMAC algorithm to verify the token signature.
  • <token> is the token returned by the START command.
  • <ttl> is the positive integer that represents the seconds that the session will live. If set to 0, the session expires immediately.

Example

SESSIONGATE.EXPIRE 'qwerty' <token> 300

Returns: OK.

Set a session payload

Command: SESSIONGATE.PSET <sign_key> <token> <payload_name> <payload_data>

  • <sign_key> is the secret string used by the HMAC algorithm to verify the token signature.
  • <token> is the token returned by the START command.
  • <payload_name> is the payload name that is used to identify the payload data.
  • <payload_data> is the payload data. It can be any string, for example, a JSON stringified object.

Example

SESSIONGATE.PSET 'qwerty' <token> 'user' '{"name":"John Doe"}'

Returns: OK.

Get a session payload

Command: SESSIONGATE.PGET <sign_key> <token> <payload_name>

  • <sign_key> is the secret string used by the HMAC algorithm to verify the token signature.
  • <token> is the token returned by the START command.
  • <payload_name> is the payload name that is used to retrieve the payload data.

Example

SESSIONGATE.PGET 'qwerty' <token> 'user'

Returns: a string containing the payload data.

Delete a session payload

Command: SESSIONGATE.PDEL <sign_key> <token> <payload_name>

  • <sign_key> is the secret string used by the HMAC algorithm to verify the token signature.
  • <token> is the token returned by the START command.
  • <payload_name> is the payload name that is used to identify the payload data being deleted.

Example

SESSIONGATE.PDEL 'qwerty' <token> 'user'

Returns: OK.

End a session

Command: SESSIONGATE.END <sign_key> <token>

  • <sign_key> is the secret string used by the HMAC algorithm to verify the token signature.
  • <token> is the token returned by the START command.

Example

SESSIONGATE.END 'qwerty' <token>

Returns: OK.

Specific language drivers

Here is a list of drivers implemented in specific languages to ease the use of the SessionGate module:

Go

https://github.com/f0rmiga/sessiongate-go

sessiongate's People

Contributors

f0rmiga avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

sessiongate's Issues

Add separate TTL to payload

Right now, payloads expire with the session.
Add the following commands:

  • SESSIONGATE.PSETEX Sets a payload with TTL
  • SESSIONGATE.PEXPIRE Sets the TTL of a payload

Add Helm chart

Enable deploying to Kubernetes with Helm. This involves publishing the Docker image.

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.