Giter VIP home page Giter VIP logo

sample_riak_erlang_client_app's Introduction

Sample Riak Erlang Application

The following is a short example of building a simple command line utility to read and write objects to Riak.

Items covered:

Setup project directory

Grab the latest Rebar

curl -O -L https://github.com/downloads/basho/rebar/rebar
chmod a+x rebar

Review the available Rebar commands

./rebar -c

Specify Riak Erlang Client dependency

Configuration options, such as dependencies, are specified in the rebar.config file.

cat > rebar.config
{deps, [
 {riakc, "1.0.*",
  {git, "git://github.com/basho/riak-erlang-client.git", "HEAD"}}
]}.

You can read about the various other rebar config options here.

Fetch the dependency

./rebar get-deps

You'll notice that rebar has also pulled down the Erlang Protobuffs application which the Riak Erlang Client depends on.

Create a new application

./rebar create-app appid=sample_riak_erlang_client_app skip_deps=true

Note the use of the command line option skip_deps=true. By default commands are executed on the current application and all dependencies. If the skip_deps option were not specified the sample_riak_erlang_client_app would have been created in our dependencies as well as in our project directory.

For this project we didn't actually need to create an application. The rebar application template (create-app) provides an .app.src file which is required for rebar to compile the project. This file is known as the application resource file. More information regarding this file can be found here.

The file looks as follows:

cat src/sample_riak_erlang_client_app.app.src 
{application, sample_riak_erlang_client_app,
  [
    {description, ""},
    {vsn, "1"},
    {registered, []},
    {applications, [
              kernel,
              stdlib
             ]},
    {mod, { sample_riak_erlang_client_app_app, []}},
    {env, []}
]}.

Create a new module

./rebar create template=simplemod \
modid=sample_riak_erlang_client_app skip_deps=true

Unfortunately, templates are not documented very well at the moment. One needs to review the template source to determine the valid variables.

Note the use of skip_deps=true again.

Escript

We'll be building an escript compatible module for our command line tool. Documentation regarding escript is available here.

Escript modules are fairly simple, command line arguments are passed to the main/1 function in the module. Our module simply needs to export a main/1 function.

For rebar to correctly build the escript we need to add an option to our rebar.config.

echo "{escript_incl_apps, [riakc, protobuffs]}." >> rebar.config

Command Line Tool

This is a very simple command line tool to provide basic read and write access to Riak. Two commands, get and put, will be supported.

Examples:

sample_riak_erlang_client_app put bucket key value
sample_riak_erlang_client_app get bucket key

Get command

Testing

# Compile
./rebar compile

# Build escript
./rebar escriptize skip_deps=true

# Run
./sample_riak_erlang_client_app get bucket key

Put command

Testing

# Compile
./rebar compile

# Build escript
./rebar escriptize skip_deps=true

# Run
./sample_riak_erlang_client_app put bucket key "hello world"

TODO

  • Accept host and port options
  • Accept r, w, and dw options

sample_riak_erlang_client_app's People

Contributors

dreverri avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.