red v0.2.0 Red
Provides the main functions to work with Red.
Examples
iex> {:ok, _} = "@vcr2" |> Red.relation(:follow) |> Red.add!("@hex_pm")
...> "@vcr2" |> Red.relation(:follow) |> Enum.at(0)
"@hex_pm"
iex> "@vcr2" |> Red.relation(:follow) |> Red.add!(["@elixirlang", "@elixirphoenix"])
...> "@vcr2" |> Red.relation(:follow) |> Enum.count
2
iex> {:ok, _} = "@elixirlang" |> Red.relation(:follow) |> Red.add!("@vcr2")
...> "@vcr2" |> Red.relation(:follow, :in) |> Enum.count
1
iex> {:ok, _} = "@vcr2" |> Red.relation(:follow) |> Red.add!(~w(@a @b @c @d @e @f @g @h @i @j @k))
...> "@vcr2" |> Red.relation(:follow) |> Red.offset(3) |> Red.limit(5) |> Enum.to_list
["@h", "@g"]
Link to this section Summary
Functions
Adds relationships in redis
Builds a Red.Edge
representation
Builds a Red.Entity
representation
Returns the redis key corresponding to queryable passed as argument
Adds a page limit to the query being mounted
Adds a page offset to the query being mounted
Builds a Red.Query
representation from a Red.Relation
representation
Builds a Red.Relation
representation
Link to this section Functions
add!(Relationt.t, [Red.Entity.conversible_to_entity] | Red.Entity.conversible_to_entity) :: {:ok, [non_neg_integer]}
Adds relationships in redis.
Examples
iex> likes = "user#42" |> Red.relation(:like)
...> {:ok, _} = likes |> Red.add!("user#21")
...> likes |> Enum.member?("user#21")
true
iex> likes = "user#21" |> Red.relation(:like)
...> {:ok, _} = likes |> Red.add!(["user#12", "user#13"])
...> likes |> Enum.count
2
Builds a Red.Edge
representation.
Examples
iex> {:user, 42} |> Red.relation(:follow) |> Red.edge({:user, 21})
%Red.Edge{
relation: %Red.Relation{
name: :follow,
direction: :out,
entity: %Red.Entity{class: :user, id: 42}
},
target: %Red.Entity{class: :user, id: 21}
}
Builds a Red.Entity
representation.
Anything that qualifies as a Red.Entity.conversible_to_entity/0
type can be an argument.
Examples
iex> Red.entity(1)
%Red.Entity{id: 1}
iex> Red.entity({:user, 42})
%Red.Entity{class: :user, id: 42}
iex> Red.entity("user#42")
%Red.Entity{class: "user", id: "42"}
iex> Red.entity("key")
%Red.Entity{id: "key"}
iex> Red.entity(user: 42)
%Red.Entity{class: :user, id: 42}
iex> %Red.Entity{id: 1} |> Red.entity
%Red.Entity{id: 1}
Returns the redis key corresponding to queryable passed as argument.
Anything that qualifies as a Red.Query.queryable_t/0
type can be an argument.
Examples
iex> Red.key(1)
"1"
iex> Red.key({:user, 42})
"user#42"
iex> Red.key("user#42")
"user#42"
iex> Red.key("key")
"key"
iex> Red.key(user: 42)
"user#42"
iex> %Red.Entity{class: :user, id: 42} |> Red.key
"user#42"
iex> {:user, 42} |> Red.relation(:follow, :in) |> Red.key
"user#42:follow:in"
iex> [user: 42] |> Red.relation(:follow) |> Red.key
"user#42:follow:out"
limit(Red.Relation.t | Red.Query.t, pos_integer | -1) :: Red.Query.t
Adds a page limit to the query being mounted.
Examples
iex> {:user, 42} |> Red.relation(:like) |> Red.limit(80)
%Red.Query{
queryable: %Red.Relation{
name: :like,
direction: :out,
entity: %Red.Entity{class: :user, id: 42}
},
meta: %Red.Query.Meta{
limit: 80,
offset: 0
}
}
offset(Red.Relation.t | Red.Query.t, non_neg_integer) :: Red.Query.t
Adds a page offset to the query being mounted.
Examples
iex> {:user, 42} |> Red.relation(:like) |> Red.offset(21)
%Red.Query{
queryable: %Red.Relation{
name: :like,
direction: :out,
entity: %Red.Entity{class: :user, id: 42}
},
meta: %Red.Query.Meta{
limit: -1,
offset: 21
}
}
Builds a Red.Query
representation from a Red.Relation
representation.
Examples
iex> {:user, 42} |> Red.relation(:follow) |> Red.query
%Red.Query{
queryable: %Red.Relation{
name: :follow,
direction: :out,
entity: %Red.Entity{class: :user, id: 42}
},
meta: %Red.Query.Meta{
limit: -1,
offset: 0
}
}
relation(Red.Entity.conversible_to_entity, Red.Relation.name_t, :in | :out) :: Red.Relation.t
Builds a Red.Relation
representation.
Examples
iex> "user#42" |> Red.relation(:follow)
%Red.Relation{
name: :follow,
direction: :out,
entity: %Red.Entity{class: "user", id: "42"}
}
iex> {:user, 42} |> Red.relation(:follow, :in)
%Red.Relation{
name: :follow,
direction: :in,
entity: %Red.Entity{class: :user, id: 42}
}
iex> "user#42" |> Red.relation(:follow, :out)
%Red.Relation{
name: :follow,
direction: :out,
entity: %Red.Entity{class: "user", id: "42"}
}