Skip to content

Instantly share code, notes, and snippets.

View michael-grunder's full-sized avatar
💭
Testing in production

Michael Grunder michael-grunder

💭
Testing in production
View GitHub Profile
@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;
@michael-grunder
michael-grunder / check_hiredis.c
Created January 2, 2023 20:37
Simple hiredis example. Compile with `gcc -Wall -ocheck-hiredis check_hiredis.c -lhiredis`
#include <stdlib.h>
#include <hiredis/hiredis.h>
int main() {
redisContext *c = redisConnect("127.0.0.1", 6379);
// Short circuit if we fail to allocate a redisContext or if it
// reports an error state.
if (c == NULL || c->err) {
@michael-grunder
michael-grunder / li1c.c
Created December 13, 2022 05:24
The exact same functionality, but not waiting for carriage return
#include <stdio.h>
#include <termios.h>
#include <unistd.h>
/* If it is the carriage return thing, here is the exact same
* functionality, but also setting termio.
* NOTE: I have no idea what the performance implications of calling
* `tcgetaddr`/`tcsetaddr` for this little routine would be
* or whether it is acceptable in your situation.
*/
@michael-grunder
michael-grunder / getc.c
Created December 13, 2022 05:16
Changing terminal settings so `getc` doesn't wait for the user to press ENTER
// Compile with: cc -Wall -otermio termio.c
#include <stdio.h>
#include <termios.h>
#include <unistd.h>
int main(void) {
static struct termios oldt, newt;
/* Get current termio settings */
@michael-grunder
michael-grunder / Dockerfile
Created October 26, 2022 21:45
Install PHP 8.0 and Relay on vanilla RockyLinux 8
FROM rockylinux:8 as build0
RUN yum -y update && yum -y install gcc make autoconf gcc-c++ git wget libzstd-devel libxml2-devel \
sqlite-devel
FROM build0 as build1
# Download build and install PHP 8.0
RUN mkdir -p /root/dev && cd /root/dev/ && \
cd /root/dev/ && wget -q "https://www.php.net/distributions/php-8.0.14.tar.gz" && \
@michael-grunder
michael-grunder / gen_varkey_cmd.c
Created September 27, 2022 17:26
With a pointer timeout
static int gen_varkey_cmd(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock,
char *kw, int kw_len, int min_argc, int has_timeout,
char **cmd, int *cmd_len, short *slot)
{
zval *z_args, *z_ele, *ztimeout = NULL;
HashTable *ht_arr;
char *key;
int key_free, i, tail;
size_t key_len;
int single_array = 0, argc = ZEND_NUM_ARGS();
@michael-grunder
michael-grunder / bind-to-device.c
Created September 7, 2022 21:28
Hiredis SO_BINDTODEVICE example.
#include "hiredis.h"
#include <assert.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <linux/if.h>
#include <errno.h>
#include <string.h>
#include <stdlib.h>
char device[IFNAMSIZ];
@michael-grunder
michael-grunder / phpredis-command-adds.txt
Created July 26, 2022 17:50
When commands were added to PhpRedis (4.3.0 was released 2019-03-13)
637b1c4 1258108773 2009-11-13 TYPE
637b1c4 1258108773 2009-11-13 RPUSH
637b1c4 1258108773 2009-11-13 SADD
637b1c4 1258108773 2009-11-13 LPUSH
637b1c4 1258108773 2009-11-13 LPOP
637b1c4 1258108773 2009-11-13 EXISTS
637b1c4 1258108773 2009-11-13 PING
637b1c4 1258108773 2009-11-13 SREM
a2d436d 1258552009 2009-11-18 RPOP
9488119 1258553043 2009-11-18 SMOVE