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
// BenchmarkBytesBufferNoReuse 2000000 790 ns/op 152 B/op 6 allocs/op
// BenchmarkBytesBufferWithReuse 5000000 675 ns/op 40 B/op 5 allocs/op
// BenchmarkBufioWriterNoReuse 1000000 2273 ns/op 4200 B/op 7 allocs/op
// BenchmarkBufioWriterWithReuse 5000000 541 ns/op 40 B/op 5 allocs/op
// BenchmarkFmt 1000000 1894 ns/op 176 B/op 5 allocs/op
package main
import (
"bufio"
"bytes"

Start master in another window with redis-server master.conf

Fill master server with 10% keys that will expire very soon and 90% keys that wont expire for a while:

% ruby fill.rb | redis-cli --pipe -p 9998
All data transferred. Waiting for the last reply...
Last reply received from server.
errors: 0, replies: 1000002

Wait a few seconds and then start slave in another window with redis-server slave.conf

// 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: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")}"