

Elixir Tutorial 02 - Adding Redis Support to our Page Fetcher
source link: https://fuzzyblog.io/blog/elixir/2016/09/15/elixir-tutorial-02-adding-redis-support-to-our-page-fetcher.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

Elixir Tutorial 02 - Adding Redis Support to our Page Fetcher
Sep 15, 2016
In my last elixir post I documented how to generate a standalone Elixir project for a page fetcher. Technically that would have been Elixir Tutorial 01 but I'm too tired right now to go back and rename it since this is my middle of the night, can't sleep coding time while on vacation.
Let's start with a description of what we're planning to build. What is a page fetcher?
A page fetcher is a bit of software that pulls content (pages) from the Internet and stores them some where for processing by something else.
So what do we actually need:
- A bit of software that runs reliably
- And doesn't require writing low level libraries as we're just not there yet with our Elixir skills
- And pulls content from Redis that describes what to fetch
- And fetches a page off from a url
- And stores it away for processing. Likely in a database or some such place
That doesn't sound so hard, does it? Here's the redis library we're going to use. Let's start by adding redis support to what we generated last time.
Change into your working directory. For me that is:
cd ~/me/fuzzygroup/elixir/page_fetcher
Now run mix test to make sure everything is still working:
mix test
Open the file mix.exs in your editor and add the following:
{:exredis, ">= 0.2.4"}
This needs to go between the [] in the defp deps routine. Think of it this way – you are updating Gemfile. That's all this is. Only its a more reliable Gemfile without the cruft and crap of bundler. I love you Ruby but good lord the packaging infrastructure lately blows monkey chunks. Not a day goes by that I don't hit some Gemfile / bundler crap.
Now run mix test again:
mix test
And you're going to see a failure like this:
sjohnson@ScottJohnsonMacbookAir:~/me/fuzzygroup/elixir/page_fetcher$ mix test
Unchecked dependencies for environment test:
* exredis (Hex package)
the dependency is not available, run "mix deps.get"
** (Mix) Can't continue due to errors on dependencies
So you're going to do what I think of as the deps dance and type:
mix deps.get
And you'll see something like this:
A new Hex version is available (0.13.0), please update with `mix local.hex`
Running dependency resolution
Dependency resolution completed
eredis: 1.0.8
exredis: 0.2.5
* Getting exredis (Hex package)
Checking package (https://repo.hex.pm/tarballs/exredis-0.2.5.tar)
Fetched package
* Getting eredis (Hex package)
Checking package (https://repo.hex.pm/tarballs/eredis-1.0.8.tar)
Fetched package
Your mileage may vary with respect to the "please update …" stuff. Please bear in mind that Hex isn't perfect at present. I've see issues but they are few and far between at least in my experience.
The next step up is to modify your project to talk to your Redis server. Do that by modifying config/config.exs with your server params. Here are mine:
config :exredis,
host: "127.0.0.1",
port: 6379,
password: "",
db: 0,
reconnect: :no_reconnect,
max_queue: :infinity
Since we're connecting on 127.0.0.1 you need to run this on the same machine where your redis server lives or adjust the ip address.
As always when you change anything run your test suite which will compile your code and show you any errors. Here's what mine looks like:
mix test
==> eredis (compile)
Compiled src/eredis_sub.erl
Compiled src/eredis_parser.erl
Compiled src/eredis_sub_client.erl
Compiled src/basho_bench_driver_erldis.erl
Compiled src/eredis.erl
Compiled src/basho_bench_driver_eredis.erl
Compiled src/eredis_client.erl
==> exredis
Compiling 5 files (.ex)
Generated exredis app
==> page_fetcher
Compiling 1 file (.ex)
Generated page_fetcher app
.
Finished in 0.05 seconds
1 test, 0 failures
Randomized with seed 697093
So at this point we have an elixir application with a supervision tree for reliability and a redis client. Given that I'm a strong believer in "deploy early; deploy often", I'll handle getting all this deployed onto an Ubuntu server. After that I'll tackle getting this to run continuously popping things from the redis queue.
All code can be found here: https://github.com/fuzzygroup/elixir_page_fetcher
Posted In: #elixir
Recommend
-
40
前言 这篇文章从区块传播策略入手,介绍新区块是如何传播到远端节点,以及新区块加入到远端节点本地链的过程,同时会介绍fetcher模块,fetcher的功能是处理Peer通知的区块信息。在介绍过程中,还会涉及到p2p,eth等模块,不会...
-
11
simple-covid19-json-fetcher - npm This website stores cookies on your computer. These cookies are used to collect information about how...
-
13
Elixir Tutorial 04 Actually Writing Some Code For Our Page Fetcher Sep 22, 2016 Note: I'm very much figuring this out on the fly and you're going to see stuff in here where you go "He's wrong! He's fla...
-
4
Elixir Tutorial 03 - Deploying to Ubuntu Sep 16, 2016 As discussed in my last Elixir Tutoria...
-
5
Adding ActionScript support to Xcode Tutorial Monday, August 30, 2004 The guys over at pixelconsumption have put together an excellent tutorial on how to add...
-
6
死磕以太坊源码分析之 Fetcher 同步 Fetcher 功能概述 区块数据同步分为被动同步和主动同步: 被动同步是指本地节点收到其他节点的一些广播的消息,然后请求区块信息。 ...
-
7
Build an Elixir Redis Server that's 100x faster than HTTPNovember 9, 2021 · 7 min readKyle HansonCEO of StatetraceNeed a fast...
-
5
FetcherSearch easily across all your social-mediaFetcher queries and combines relevant social-media posts into one beautiful page. It ensures you stay updated by scanning for new...
-
12
Data Fetcher Alternatives For Big Data Enrichment
-
9
Top Liked Posts Great ROM. I just flashed it, and it feels smooth and nice. I found a few small issues though. - Before I had a PIN...
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK