Skip to content

Instantly share code, notes, and snippets.

@dspezia
dspezia / tst.cpp
Created December 10, 2011 12:45
Variadic rpush C++ hiredis example
#include <iostream>
#include <vector>
#include <string>
#include <stdexcept>
#include <hiredis.h>
using namespace std;
@dspezia
dspezia / Makefile
Created February 23, 2012 15:50
Example of pipelining with hiredis
OBJ = genload.o
BINS = genload
CC=g++
OPTIMIZATION?=-O3
CFLAGS?=$(OPTIMIZATION) $(ARCH) $(PROF) -I ../hiredis
CCLINK?=-pthread
LDFLAGS?=-L../hiredis -lhiredis -lm
OBJ = example.o
@dspezia
dspezia / Example log
Created April 9, 2012 15:17
Assessing pending activity of a Redis server
> ~/tcp_redis_monitor.py 6379
Timestamp Nb TX bytes RX bytes TX RMA RX RMA
1333983822.943 1 0 0 0.000 0.000
1333983823.193 1 0 0 0.000 0.000
1333983824.194 1 0 0 0.000 0.000
1333983825.195 1 0 0 0.000 0.000
1333983826.196 1 0 0 0.000 0.000
@dspezia
dspezia / gist:993738
Created May 26, 2011 18:36
Example of pipelining with async hiredis
/* Code borrowed from hiredis examples */
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <signal.h>
#include "hiredis.h"
#include "async.h"
#include "adapters/ae.h"
@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 / 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 / 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 {
@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 / gist:1771342
Created February 8, 2012 17:19
Example of Redis zset + key iteration + pipelining in Python
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# ----------------------------------------------------
import redis, random
POOL = redis.ConnectionPool(host='localhost', port=6379, db=0)
NUSERS = 10000
NTAGS = 500
@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;