Skip to content

Instantly share code, notes, and snippets.

View michael-grunder's full-sized avatar

Michael Grunder michael-grunder

View GitHub Profile
@michael-grunder
michael-grunder / ck_rhs_mixed_benchmark.c
Created July 21, 2026 19:46
Granular ck_rhs_t benchmark script
/*
* Copyright 2026 Michael Grunder.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
@michael-grunder
michael-grunder / ck_rhs_fas_grow_reproducer.c
Created July 21, 2026 18:01
Reproducer illustrating losing a key with `ck_rhs_fas`
/*
* Reproduce a stale map pointer in ck_rhs_fas after Robin Hood relocation
* grows the table.
*
* There are three useful outcomes:
*
* 1. Unpatched master loses a key before ck_rhs_fas can reach the growth
* path, demonstrating the pre-existing Robin Hood probe-depth bug.
* 2. With only the probe-depth fix, ck_rhs_fas reaches the growth path and
* loses the replacement by restarting with a pointer to the retired map.
@michael-grunder
michael-grunder / ck_rhs_probe_bound_reproducer.c
Last active July 20, 2026 02:34
ck_rhs_t robinhood probing issue reproducer
/*
* Standalone reproducer for a ck_rhs probe-bound corruption. It expects the
* usual ck_rhs configuration where an 8-bit atomic stores the probe bound.
*
* Build from a configured ck checkout with:
* cc -std=c99 -O2 -Iinclude ck_rhs_probe_bound_reproducer.c \
* src/ck_rhs.c -o ck_rhs_probe_bound_reproducer
* Or just:
* cc -O2 -g3 ck_rhs_probe_bound_reproducer.c -lck -o ck_rhs_probe_reproducer
*/
function export_redis(RedisClient $redis, string $targetPath): array
{
ensureDir(dirname($targetPath));
$handle = fopen($targetPath, 'wb');
if ($handle === false) {
throw new RuntimeException("Unable to write Redis export: {$targetPath}");
}
$types = [
Storage: /var/lib/systemd/coredump/core.php.1000.dc4d8d901afc458882fef3a2cb5a2225.16488.1767373281000000.zst (present)
Size on Disk: 1.2M
Message: Process 16488 (php) of user 1000 dumped core.
Module libgomp.so.1 from deb gcc-14-14.2.0-4ubuntu2~24.04.amd64
Module libzstd.so.1 from deb libzstd-1.5.5+dfsg2-2build1.1.amd64
Module libgcc_s.so.1 from deb gcc-14-14.2.0-4ubuntu2~24.04.amd64
Module libstdc++.so.6 from deb gcc-14-14.2.0-4ubuntu2~24.04.amd64
Stack trace of thread 16488:
#0 0x00007a68c5b50ce9 relayIncrSharedStats (relay.so + 0xe3ce9)
@michael-grunder
michael-grunder / Dockerfile
Created April 2, 2025 18:55
Dockerfile to use PhpRedis' session handler via tls and password
FROM debian:latest
RUN apt-get update && apt-get install -y \
php-cli \
php-dev \
php-pear \
gcc \
make \
redis \
openssl \
@michael-grunder
michael-grunder / gist:9676b8ef2eb4c199752b2aa0bc1707df
Created August 30, 2024 18:17
PHP 8.4 alpha1 + PhpRedis Dockerfile
FROM ubuntu:22.04
ENV PHP_VERSION=8.4.0alpha1
ENV PHPREDIS_VERSION=develop
RUN apt-get update && apt-get install -y \
build-essential \
wget \
curl \
libxml2-dev \
@michael-grunder
michael-grunder / count-cluster-slots.php
Last active March 7, 2024 18:32
Is PhpRedis calling `CLUSTER SLOTS`
<?php
function accCommandCounts(array &$acc, array $stats) {
$re_cmd = '/cmdstat_([a-zA-Z]+)\|?([a-zA-Z]*)/';
$re_num = '/^calls=(\d+).*/';
foreach ($stats as $cmd => $info) {
if ( ! preg_match($re_cmd, $cmd, $matches))
die("Malformed command name\n");
@michael-grunder
michael-grunder / convert.c
Created November 29, 2023 04:15
Toy program to convert uint8_t strings into uint8_t values.
#include <stdio.h>
#include <stdint.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <sys/time.h>
#include <locale.h>
#define MAX_DIGITS 3
@michael-grunder
michael-grunder / hiredis-binary-example.c
Created May 9, 2023 18:40
A small example storing binary data in a Redis set with hiredis.
// Compile with: cc -Wall -ggdb3 -o hiredis-binary-example hiredis-binary-example.c -lhiredis
#include <stdio.h>
#include <hiredis/hiredis.h>
#include <stddef.h>
#include <stdlib.h>
#include <string.h>
struct binaryData {
char *str;