Object Oriented Keys for Redis
0.1.0 Latest release released


Object Oriented Keys for Redis.


If you are familiar with databases like Redis and libraries like Ohm you already know how important it is to craft the keys that will hold the data.

require "resp"

resp ="redis://localhost:6379")"SADD", "event:3:attendees", "Albert")"SMEMBERS", "event:3:attendees") #=> ["Albert"]

It is a design pattern in key-value databases to use the key to simulate structure, and you can read more about this in the case study for a Twitter clone.

Nest helps you generate those keys by providing chainable namespaces that are already connected to Redis:

require "nest"

resp ="redis://localhost:6379")

event ="event", resp)
event[3][:attendees].call("SADD", "Albert")
event[3][:attendees].call("SMEMBERS") #=> ["Albert"]

You can also create the Nest instance without passing a Resp client, and just provide it when invoking the call method:

require "nest"

resp ="redis://localhost:6379")

event ="event")
event[3][:attendees].call(resp, "SADD", "Albert")
event[3][:attendees].call(resp, "SMEMBERS") #=> ["Albert"]


To create a new namespace:

ns ="foo")

ns.to_s #=> "foo"

ns["bar"].to_s #=> "foo:bar"

ns["bar"]["baz"]["qux"].to_s #=> "foo:bar:baz:qux"

And you can use any object as a key, not only strings:

ns[:bar][42].to_s #=> "foo:bar:42"

In a more realistic tone, lets assume you are working with Redis and dealing with events:

events ="events", resp)

id = events[:id].call("INCR")

events[id][:attendees].call("SADD", "Albert")

meetup = events[id]

meetup[:attendees].call("SMEMBERS") #=> ["Albert"]

Nest allows you to execute all the Redis commands that expect a key as the first parameter.


Add this to your application's shard.yml:

    github: soveran/nest-crystal
    branch: master
  github: soveran/nest-crystal
  version: ~> 0.1.0
License MIT
Crystal none


Dependencies 1

  • resp master
    {'branch' => 'master', 'github' => 'soveran/resp-crystal'}

Development Dependencies 1

Dependents 1

Last synced .
search fire star recently