Skip to content

Instantly share code, notes, and snippets.

@dspezia
dspezia / t.go
Created July 22, 2020 22:52
Example Go frequency measurement
package main
import "bytes"
import "time"
import "fmt"
func ClusterSlot(key []byte) uint16 {
if start := bytes.IndexByte(key, '{'); start >= 0 {
if end := bytes.IndexByte(key[start+1:], '}'); end > 0 {
Sun Jun 14 18:23:12 CEST 2015
stkbarPos=0 len(stkbar)=1 goid=1025 gcphase=2
fatal error: g already has stack barriers
runtime stack:
runtime.throw(0x7403d0, 0x1c)
/data2/ds/local/go/src/runtime/panic.go:527 +0x96
runtime.scanstack(0xc209a40840)
/data2/ds/local/go/src/runtime/mgcmark.go:334 +0x4f4
runtime.gcphasework(0xc209a40840)
fatal error: unexpected signal during runtime execution
[signal 0xb code=0x80 addr=0x0 pc=0x41be2a]
runtime stack:
runtime.throw(0x7586d0, 0x2a)
/data2/ds/local/go/src/runtime/panic.go:527 +0x96
runtime.sigpanic()
/data2/ds/local/go/src/runtime/sigpanic_unix.go:12 +0x5a
runtime.mSpan_Sweep(0x7f9a7c0b8c00, 0xa1900000a00, 0xc01)
/data2/ds/local/go/src/runtime/mgcsweep.go:182 +0x1ba
@dspezia
dspezia / example.c
Created April 25, 2013 13:41
Example if hiredis subscribe with libevent
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <signal.h>
#include "hiredis.h"
#include "async.h"
#include "adapters/libevent.h"
void subCallback(redisAsyncContext *c, void *r, void *priv) {
redisReply *reply = r;
@dspezia
dspezia / example.c
Created November 26, 2012 18:26
Example of Redis zset polling daemon
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <signal.h>
#include <time.h>
#include "hiredis.h"
#include "async.h"
#include "adapters/ae.h"
#include "sha1.h"
@dspezia
dspezia / entropy.c
Created October 4, 2012 08:37
Dead simple (unsafe) entropy generator for Linux /dev/random
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <fcntl.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/ioctl.h>
@dspezia
dspezia / db.c
Created August 4, 2012 15:01
Redis hack to get notified when a key expire
// Change propagateExpire function in db.c as follows:
void propagateExpire(redisDb *db, robj *key) {
/* HORRIBLE HACK STARTS HERE */
/* robj *argv[2]; */
robj *argv[3];
/* HORRIBLE HACK ENDS HERE */
argv[0] = shared.del;
@dspezia
dspezia / intset.js
Created June 19, 2012 20:06
Evaluating memory consumption of 1M targeted tag sets
var redis = require('redis')
var rc = redis.createClient(6379, 'localhost');
function create( target, callback )
{
x = []
for ( var i=0; i<40; ++i )
{
// Only 100K entries in the reverse index
var n = 1000*Math.round(Math.random()*100000);
@dspezia
dspezia / ha.cfg
Created May 10, 2012 14:46
haproxy to target redis
global
daemon
maxconn 256
defaults
mode tcp
timeout connect 5000ms
timeout client 50000ms
timeout server 50000ms
@dspezia
dspezia / ex3.rb
Created May 3, 2012 17:53
Ruby example of pipelining with the distributed client
require 'rubygems'
gem 'redis', '3.0.0.rc1'
require 'redis'
require 'redis/distributed'
# Create a client for 3 distributed Redis instances
$r = Redis::Distributed.new %w[redis://localhost:6380 redis://localhost:6381 redis://localhost:6382]
# Set 1000 items in distributed Redis