securing and showing a redis server to the world


Bookmark and Share

redis logo

Redis

Redis is an in memory based key value data structure server. They keywords here are in-memory (RAM) and Key – Value (Hash). RAM being the easily accessible memory location for your CPU, and hash being the most accissable data-structure a combination of both makes it lethal. It was developed by an Italian developer named Salvatore Sanfilippo, in 2009.

Such a system is useful in multiple scenarios. Especially in cases where key is readily available, constant and not changing. Some example use cases being. In a rails projects Redis is used at multiple places for example:

  • Backend of action cable which is used to provide notifications (pub/sub)
  • Queue system used by background workers (Sidekiq, Resque)
  • Web Caching
  • Session Store – sharing user session across all the load balanced servers
  • Fast accessible meta data catalog for your inventory or tool
  • Counting – Redis offers a fast method to increment and decrement value. Being an in-memory storage does add

 

Coming back to the topic of this article, most self hosted rails applications starts off by installing redis in the same server as your rails application. In fact sidekiq, crontab (for scheduling tasks) would all be on the …

Read More

Managing threads with Queue and SizedQueue


Bookmark and Share

Threads in Ruby

To make our applications do multiple things faster at the same time, we can use Ruby threads. For a long-running application, re-using a pool of such threads can provide great performance benefits. Thread pool is a way to have a fixed set of threads doing the work, instead of creating new ones each time.

Considering a simple program as below, we realize the importance of threads.

You will get the sum of each array as output but the sleep(4) instruction will pause execution for 4 seconds and then continue. Thus, group1 will get the sum after 4 seconds, group2 after 8 seconds and so on, which is not feasible. In such cases, it is more economical to have threads, since we can have the sum of each array calculated independently.

Threads allow us to execute different parts of our program independently. For implementing threads, after initializing each array,

The add_element method definition is same but we wrapped method call in a Thread.new block.

Now, instead of getting the sum of each array after 4 seconds, 8 seconds and 12 seconds respectively, you will get the sum of all arrays after 4 seconds. This indicates better performance and efficiency …

Read More

PRY- Alternative for IRB


Bookmark and Share

What is PRY? Why do we need PRY? Why read an article on PRY? Some of these questions might pop up in your mind when you read the title of this blog. Let me explain why you should be knowing about PRY.

 

PRY

 

PRY is an attempt to remake IRB, the interactive Ruby interpreter, in a way that makes more sense for mordern programmers. Some of the most important features of PRY are syntax highlighting, code indentation and code debugging. In other words, instead of coding inside a REPL session, you can start a REPL session inside your code execution with the help of PRY.

Installing PRY

Since PRY is a Ruby gem, installing it is straightforward. The following commands will work:

Features

PRY colorizes the syntax as it is typed into the console just like most mordern editors. In addition to this, PRY also auto-indents code thus allowing ensuring that the ‘end’ words line up with the lines that open the block.

pry(main) > class User
pry(main)*   def greet
pry(main)*     puts “Hello world”
pry(main)*   end
pry(main)* end

Another cool feature of PRY, as per my opinion, is it’s ability to show a method’s documentation and source code …

Read More

Jenkins – Continuous Integration


Bookmark and Share

header_logo (1)

In this article am going to explain about Jenkins. So what is jenkins?

Jenkins is the leading open source continuous integration server. Built with java. Jenkin is a CI so first we need to know what is continuos integration. Nowadays developers are working from different corners of the world. When same code is modified by different users the chance for conflicts are very high, this consume large amout of time to solve the issue.To avoid this we use continuos integration. This is a practice of merging all developers working copies into a repository many times aday. There are different continuous integration tools available, some of them are Bamboo, Apache Continuum, DeployBot, Hudson, Jenkins etc

So many continuous integrations tools are available then why we choose Jenkins?

Jenkins is an extensible continuous integration engine forked from Hudson and Hudson team has moved to develop Jenkins, large number of plugins are available in Jenkins and the authers are choosen to support their plugins on Jenkins, Jenkins make incremental itrative improvement to the code,
Jenkins provide hundreds of plugins to …

Read More

Setting Up RSpec in Rails Application


Bookmark and Share

This article describes the RSpec setup process in your Rails application.

Installing RSpec

When generating a new Rails project, just add the flag –skip-test-unit to supress creation of the test directory associated with the default Test::Unit framework as won’t be needing that.

In the Gemfile, add:

RSpec-Rails has a dependency to RSpec, so we don’t need to include it separately.

Yeah, we need it in development env too. Let’s see why :

  • The development mode RSpec files add RSpec-specific generators
  • Test mode includes files to run the tests

Once you have run bundle install, Run this snippet to configure Rails to use RSpec in place of Test::Unit rails generate rspec:install

This single command would generate you 4 new files :

We’ll cover more in detail regarding those later.

Updating the test database

Check for pending migrations and load the test schema rake db:test:prepare

N.B Preparing your test database

Run your test suit

rspec

Yup, Its simple as that… 🙂

Read More