Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up

Redis adapter for Yggdrasil

License

NotificationsYou must be signed in to change notification settings

gmtprime/yggdrasil_redis

Repository files navigation

Build StatusHex pmhex.pm downloads

This project is a Redis adapter forYggdrasil publisher/subscriber.

Small example

The following example uses Redis adapter to distribute messages:

iex(1)>channel=%Yggdrasil.Channel{name:"some_channel",adapter::redis}iex(2)>Yggdrasil.subscribe(channel)iex(3)>flush(){:Y_CONNECTED,%Yggdrasil.Channel{(...)}}

and to publish a message for the subscribers:

iex(4)>Yggdrasil.publish(channel,"message")iex(5)>flush(){:Y_EVENT,%Yggdrasil.Channel{(...)},"message"}

When the subscriber wants to stop receiving messages, then it can unsubscribefrom the channel:

iex(6)>Yggdrasil.unsubscribe(channel)iex(7)>flush(){:Y_DISCONNECTED,%Yggdrasil.Channel{(...)}}

Redis adapter

The Redis adapter has the following rules:

  • Theadapter name is identified by the atom:redis.
  • The channelname must be a string.
  • Thetransformer must encode to a string. From thetransformers providedit defaults to:default, but:json can also be used.
  • Anybackend can be used (by default is:default).

The following is an example of a valid channel for both publishers andsubscribers:

%Yggdrasil.Channel{name:"redis_channel_name",adapter::redis,transformer::json}

It will expect valid JSONs from Redis and it will write valid JSONs in Redis.

Redis configuration

Uses the list of options forRedix, but the more relevant optuons are shownbelow:

  • hostname - Redis hostname (defaults to"localhost").
  • port - Redis port (defaults to6379).
  • password - Redis password (defaults to"").

The following shows a configuration with and without namespace:

# Without namespaceconfig:yggdrasil,redis:[hostname:"redis.zero"]# With namespaceconfig:yggdrasil,RedisOne,redis:[hostname:"redis.one",port:1234]

Also the options can be provided as OS environment variables. The availablevariables are:

  • YGGDRASIL_REDIS_HOSTNAME or<NAMESPACE>_YGGDRASIL_REDIS_HOSTNAME.
  • YGGDRASIL_REDIS_PORT or<NAMESPACE>_YGGDRASIL_REDIS_PORT.
  • YGGDRASIL_REDIS_PASSWORD or<NAMESPACE>_YGGDRASIL_REDIS_PASSWORD.
  • YGGDRASIL_REDIS_DATABASE or<NAMESPACE>_YGGDRASIL_REDIS_DATABASE.

where<NAMESPACE> is the snakecase of the namespace chosen e.g. for thenamespaceRedisTwo, you would useREDIS_TWO as namespace in the OSenvironment variable.

Installation

Using this Redis adapter withYggdrasil is a matter of adding the availablehex package to yourmix.exs file e.g:

defdepsdo[{:yggdrasil_redis,"~> 4.1"}]end

Running the tests

Adocker-compose.yml file is provided with the project. If you don't have aRedis database, but you do have Docker installed, then just do:

$ docker-compose up --build

And in another shell run:

$ mix deps.get$ mix test

Relevant projects used

Author

Alexander de Sousa.

License

Yggdrasil is released under the MIT License. See the LICENSE file for furtherdetails.

Packages

No packages published

Languages


[8]ページ先頭

©2009-2025 Movatter.jp