Ruby github.com

Higher-level Ruby data structures built on Redis  ↦

Kredis (Keyed Redis) comes from the Rails team and lets you interact with Redis-backed keys as coherent Ruby objects rather than isolated procedural commands. Here’s what that might look like when dealing with strings, integers, and JSON:

string = Kredis.string "mystring"
string.value = "hello world!"  # => SET mystring "hello world"
"hello world!" == string.value # => GET mystring

integer = Kredis.integer "myinteger"
integer.value = 5  # => SET myinteger "5"
5 == integer.value # => GET myinteger

json = Kredis.json "myjson"
json.value = { "one" => 1, "two" => "2" }  # => SET myjson "{\"one\":1,\"two\":\"2\"}"
{ "one" => 1, "two" => "2" } == json.value  # => GET myjson

(There are also Redis-backed data structures for counters, enums, flags, lists, unique lists, sets, and slots.)

I love the idea of being able to think at the layer of objects instead of database record manipulation. Dark is doing something similar with its persistence engine, which we discuss on an upcoming episode of The Changelog.


Discussion

Sign in or Join to comment or subscribe

Player art
  0:00 / 0:00