参考页面

https://github.com/mperham/sidekiq

https://github.com/mperham/sidekiq/wiki/Getting-Started

强烈推荐这个视频

https://www.youtube.com/watch?v=bfPb1zD91Rg&index=1&list=PLjeHh2LSCFrWGT5uVjUuFKAcrcj5kSai1

$mkdir  sidekiq_playground
$cd sidekiq_playground/ $vim Gemfile

添加一个gem

source "https://rubygems.org"

gem "sidekiq"

新增worker.rb

vim worker.rb
require 'sidekiq'

Sidekiq.configure_client do |config|
config.redis = { db: 1 }
end Sidekiq.configure_server do |config|
config.redis = { db: 1 }
end class OurWorker
include Sidekiq::Worker def perform(complexity)
case complexity
when "super_hard"
sleep 20
puts "super hard! Really took quite a bit of effort"
when "hard"
sleep 10
puts "hard! That was o bit of work"
else
sleep 1
puts "That wasn't a lot of effort"
end
end
end

安装redis,启动sidekiq

$sudo apt-get install redis-server
$ bundle exec sidekiq -r ./worker.rb

执行一下

$ bundle exec irb -r ./worker.rb
irb(main):001:0> OurWorker.perform_async("easy")
=> "d40dc832d93f50c00afd2ab4"
irb(main):002:0> OurWorker.perform_async("hard") //立刻执行
=> "33356c6a0c7cd55047d40670"

irb(main):003:0> OurWorker.perform_in(5,"easy")   //5秒后执行
  => "7a517f4305ff6105aa408b4f"

 

查看启动页面里的输出

$ bundle exec sidekiq -r ./worker.rb
2016-03-31T07:11:15.792Z 30945 TID-gnktzwzl4 INFO: Booting Sidekiq 4.1.1 with redis options {:db=>1, :url=>nil} m,
`$b
.ss, $$: .,d$
`$$P,d$P' .,md$P"'
,$$$$$bmmd$$$P^'
.d$$$$$$$$$$P'
$$^' `"^$$$' ____ _ _ _ _
$: ,$$: / ___|(_) __| | ___| | _(_) __ _
`b :$$ \___ \| |/ _` |/ _ \ |/ / |/ _` |
$$: ___) | | (_| | __/ <| | (_| |
$$ |____/|_|\__,_|\___|_|\_\_|\__, |
.d$$ |_| 2016-03-31T07:11:15.792Z 30945 TID-gnktzwzl4 INFO: Running in ruby 2.1.2p95 (2014-05-08 revision 45877) [x86_64-linux]
2016-03-31T07:11:15.792Z 30945 TID-gnktzwzl4 INFO: See LICENSE and the LGPL-3.0 for licensing details.
2016-03-31T07:11:15.792Z 30945 TID-gnktzwzl4 INFO: Upgrade to Sidekiq Pro for more features and support: http://sidekiq.org
2016-03-31T07:11:15.793Z 30945 TID-gnktzwzl4 INFO: Starting processing, hit Ctrl-C to stop
2016-03-31T07:13:17.062Z 30945 TID-gnku2xt9s OurWorker JID-d40dc832d93f50c00afd2ab4 INFO: start
That wasn't a lot of effort
2016-03-31T07:13:18.065Z 30945 TID-gnku2xt9s OurWorker JID-d40dc832d93f50c00afd2ab4 INFO: done: 1.003 sec
2016-03-31T07:14:08.887Z 30945 TID-gnktztls4 OurWorker JID-33356c6a0c7cd55047d40670 INFO: start
hard! That was o bit of work
2016-03-31T07:14:18.887Z 30945 TID-gnktztls4 OurWorker JID-33356c6a0c7cd55047d40670 INFO: done: 10.0 sec

basic use of sidekiq的更多相关文章

  1. basic use of sidekiq (2)

    vim Gemfile source "https://rubygems.org" gem "sidekiq"gem 'rack-protection' gem ...

  2. Atitit HTTP 认证机制基本验证 (Basic Authentication) 和摘要验证 (Digest Authentication)attilax总结

    Atitit HTTP认证机制基本验证 (Basic Authentication) 和摘要验证 (Digest Authentication)attilax总结 1.1. 最广泛使用的是基本验证 ( ...

  3. Basic Tutorials of Redis(9) -First Edition RedisHelper

    After learning the basic opreation of Redis,we should take some time to summarize the usage. And I w ...

  4. Basic Tutorials of Redis(8) -Transaction

    Data play an important part in our project,how can we ensure correctness of the data and prevent the ...

  5. Basic Tutorials of Redis(7) -Publish and Subscribe

    This post is mainly about the publishment and subscription in Redis.I think you may subscribe some o ...

  6. Basic Tutorials of Redis(6) - List

    Redis's List is different from C#'s List,but similar with C#'s LinkedList.Sometimes I confuse with t ...

  7. Basic Tutorials of Redis(5) - Sorted Set

    The last post is mainly about the unsorted set,in this post I will show you the sorted set playing a ...

  8. Basic Tutorials of Redis(4) -Set

    This post will introduce you to some usages of Set in Redis.The Set is a unordered set,it means that ...

  9. Basic Tutorials of Redis(3) -Hash

    When you first saw the name of Hash,what do you think?HashSet,HashTable or other data structs of C#? ...

随机推荐

  1. Object C学习笔记26-文件管理(二)

    上一篇简单的介绍了如何获取文件属性,删除,拷贝文件等,本文继续记录Object C中文件IO操作. 一. 获取文件的执行主目录 在Object C中提供了一个方法 NSHomeDirectory() ...

  2. [wikioi 1034][CTSC 1999]家园(网络流)

    由于人类对自然的疯狂破坏,人们意识到在大约2300年之后,地球不能再居住了,于是在月球上建立了新的绿地,以便在需要时移民.令人意想不到的是,2177年冬由于未知的原因,地球环境发生了连锁崩溃,人类必须 ...

  3. ThinkPHP之MVC与URL访问

    一.初探 我们在apache的www目录下创建一个文件夹,其命名为我们的应用名.然后通过入口文件生成我们的应用. 当我们用ThinkPHP创建好一个应用后,其目录结果如下所示 那么我们如何来访问我们应 ...

  4. Boostrap(2)

    网页布局 1.网格布局 网格布局就是把网页分为许多小格子,看起来像table,然后在每个小格子中放我们的内容.当然,我们也可以指定一片区域使用网格系统.网格布局主要是应用在移动设备上的,使用方法如下: ...

  5. DOM(九)使用DOM设置文本框

    1.控制用户输入的字符个数 对于单行文本框和密码输入框,可以利用maxlength属性控制用户输入的字符个数. 对于多行文本,maxlength为自定义属性,其值最多输入的字符的个数,在onkeypr ...

  6. Android音乐播放器的开发实例

    本文将引导大家做一个音乐播放器,在做这个Android开发实例的过程中,能够帮助大家进一步熟悉和掌握学过的ListView和其他一些组件.为了有更好的学习效果,其中很多功能我们手动实现,例如音乐播放的 ...

  7. session的一个问题

    <%@ page language="java" import="java.util.*,javax.servlet.http.Cookie.*" pag ...

  8. new-nav-js

    'use strict';define([ 'jquery'], function($) { var nav = { init : function() { $("#burger-menu& ...

  9. hdu1950 最长上升子序列nlogn

    简单. #include<cstdio> #include<cstring> #include<iostream> using namespace std; ; i ...

  10. hdu1853 km算法

    //hdu1853 #include<stdio.h> #include<string.h> #define INF 99999999 ][],pr[],pl[],visr[] ...