Skip to content

Instantly share code, notes, and snippets.

View tysonmote's full-sized avatar
🤠
code cowboy

Tyson Mote tysonmote

🤠
code cowboy
View GitHub Profile
// The following test runs against a local Consul server started like so:
//
// consul agent -server -bootstrap-expect 1 -data-dir /tmp/consul
//
// The test output looks like this:
//
// % go test -test.v
// === RUN TestConsul
// --- PASS: TestConsul (6.76s)
// consul_test.go:188: LastIndex after #1: 5
@tysonmote
tysonmote / gist:5301d89621d8d0f0d881
Last active August 29, 2015 14:23
Delete large Redis hashes with Ruby and Resque
$redis = Redis.new
class SafeHashDelete
@queue = :garbage_collection
BATCH_SIZE = 100
# Rename the key and queue for deletion
def self.delete(key)
newkey = "gc:hashes:#{$redis.incr("gc:index")}"
@tysonmote
tysonmote / gist:95dd2efa8c93fc0370c6
Last active August 29, 2015 14:23
Delete large Redis hashes with Ruby and Sidekiq
$redis = Redis.new
class SafeHashDelete
include Sidekiq::Worker
BATCH_SIZE = 100
# Rename the key and queue for deletion
def self.delete(key)
newkey = "gc:hashes:#{$redis.incr("gc:index")}"
@tysonmote
tysonmote / gist:9cda15bde7ffcb1e6b99
Last active February 13, 2017 22:49
Delete large Redis lists with Ruby and Resque
$redis = Redis.new
class SafeListDelete
@queue = :garbage_collection
BATCH_SIZE = 100
# Rename the key and queue for deletion
def self.delete(key)
newkey = "gc:lists:#{$redis.incr("gc:index")}"
@tysonmote
tysonmote / gist:e2d915ef4f8ca4247cea
Last active August 29, 2015 14:23
Delete large Redis lists with Ruby and Sidekiq
$redis = Redis.new
class SafeListDelete
include Sidekiq::Worker
BATCH_SIZE = 100
# Rename the key and queue for deletion
def self.delete(key)
newkey = "gc:lists:#{$redis.incr("gc:index")}"
@tysonmote
tysonmote / gist:c02b0523c42ae60c27d1
Last active August 29, 2015 14:23
Delete large Redis sets with Ruby and Resque
$redis = Redis.new
class SafeSetDelete
@queue = :garbage_collection
BATCH_SIZE = 100
# Rename the key and queue for deletion
def self.delete(key)
newkey = "gc:sets:#{$redis.incr("gc:index")}"
@tysonmote
tysonmote / gist:20df8fb55a74cd193e9a
Last active August 29, 2015 14:23
Delete large Redis sets with Ruby and Sidekiq
$redis = Redis.new
class SafeSetDelete
include Sidekiq::Worker
BATCH_SIZE = 100
# Rename the key and queue for deletion
def self.delete(key)
newkey = "gc:sets:#{$redis.incr("gc:index")}"
@tysonmote
tysonmote / gist:8c9f4bae25aa8b57dbf3
Created June 16, 2015 23:30
Delete large Redis sorted sets with Ruby and Sidekiq
$redis = Redis.new
class SafeSortedSetDelete
include Sidekiq::Worker
BATCH_SIZE = 100
# Rename the key and queue for deletion
def self.delete(key)
newkey = "gc:zsets:#{$redis.incr("gc:index")}"
@tysonmote
tysonmote / gist:1fa32995b25d49baddac
Created June 16, 2015 23:37
Delete large Redis sorted sets with Ruby and Resque
$redis = Redis.new
class SafeSortedSetDelete
@queue = :garbage_collection
BATCH_SIZE = 100
# Rename the key and queue for deletion
def self.delete(key)
newkey = "gc:zsets:#{$redis.incr("gc:index")}"
@tysonmote
tysonmote / keys.rb
Last active January 2, 2019 23:18
Utility functions for performing operations on large Redis keyspaces
require 'redis'
REDIS = Redis.new( url: "..." )
def each_keys_chunk( pattern = nil, &block )
opts = { count: 100 }
opts[:match] = pattern if pattern
cursor = 0
loop do
cursor, keys = REDIS.scan( cursor, opts )