All Projects → leafo → lapis-redis

leafo / lapis-redis

Licence: other
Redis integration for Lapis

Programming Languages

lua
6591 projects
MoonScript
45 projects
Makefile
30231 projects

lapis-redis

This module is used for integrating Redis with Lapis. It uses the lua-resty-redis module.

Installing

$ luarocks install lapis-redis

Configuring

-- config.moon

config "development", ->
  redis {
    host: "127.0.0.1"
    port: 6379
  }

Connecting

The function get_redis can be used to get the current request's Redis connection. If there's not connection established for the request a new one will be opened. After the request completes the Redis connection will automatically be recycled for future requests.

The return value of get_redis is a connected lua-resty-redis object.

import get_redis from require "lapis.redis"

class App extends lapis.Application
  "/": =>
    redis = get_redis!
    redis\set "hello", "world"

    redis\get "hello"

Redis cache

You can use Redis as a cache using the Lapis caching API.

import cached from require "lapis.cache"
import redis_cache from require "lapis.redis"

class App extends lapis.Application
  "/hello": cached {
    dict: redis_cache "cache-prefix"
    =>
      @html ->
        div "hello"
  }
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].