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
➜ test gcc-4.8 -O2 pow2.c -o pow2-gcc
➜ test ./pow2-gcc 36000000
1000000 => old=0.018063; new=0.007069 [new faster by 0.010994]
1500000 => old=0.020696; new=0.006992 [new faster by 0.013704]
2000000 => old=0.027240; new=0.009577 [new faster by 0.017663]
2500000 => old=0.031611; new=0.012714 [new faster by 0.018897]
3000000 => old=0.039922; new=0.015066 [new faster by 0.024856]
3500000 => old=0.048778; new=0.021769 [new faster by 0.027009]
4000000 => old=0.053985; new=0.022569 [new faster by 0.031416]
4500000 => old=0.063733; new=0.027154 [new faster by 0.036579]
<?php
/* This might change, but you can set it up this way (by passing an array of seeds) */
$c = new RedisCluster(
NULL,
array('127.0.0.1:7000','127.0.0.1:7001','127.0.0.1:7002','127.0.0.1:7003'),
0, 0
);
/* PHP has a custom ini mechanism, so you can define one by name in 'redis.ini',
127.0.0.1:7000> get foo
(error) MOVED 12182 127.0.0.1:7002
127.0.0.1:7000> scan 0 match "foo"
1) "6"
2) (empty list or set)
127.0.0.1:7000>
#include <hiredis/hiredis.h>
#include <stdio.h>
#include <time.h>
static void timeoutToTimeval(struct timeval *tv, double timeout) {
tv->tv_sec = (time_t)timeout;
tv->tv_usec = (int)((timeout - tv->tv_sec) * 1000000);
}
int main(int argc, const char **argv) {
@michael-grunder
michael-grunder / test.cs
Created May 12, 2016 23:37
seems to work as expected
using System;
namespace wutwut
{
class MyClass {
public void MyFunction(int a, int b) {
Console.WriteLine("In prototype that takes two integers: {0}, {1}", a, b);
}
public void MyFunction(int[] numbers) {
//
// 3.0.0
//
127.0.0.1:7000> set key2 val2
OK
127.0.0.1:7000> set key3 val3
OK
127.0.0.1:7000> multi
OK
+/* Helper to get the long value stored in a zval, whether it's actually stored
+ * as a long or is a string that contains a long */
+static int zval_get_long(zval *zv, long *lval)
+{
+ /* If it's already a long, just set and return success */
+ if (Z_TYPE_P(zv) == IS_LONG) {
+ *lval = Z_LVAL_P(zv);
+ return SUCCESS;
+ }
+
@michael-grunder
michael-grunder / poptest.c
Created February 14, 2017 21:47
Hiredis BLPOP in a thread
#include <stdio.h>
#include <string.h>
#include <pthread.h>
#include <hiredis/hiredis.h>
void *popWorker(void *context) {
const char *channel = (char*)context;
struct timeval tv = {1, 0};
redisContext *c;
redisReply *r;
@michael-grunder
michael-grunder / gist:bc683c2ab1263f57fcab2218cbd67b95
Created April 14, 2017 04:36
redis array unit test valgrind results
==2541== Memcheck, a memory error detector
==2541== Copyright (C) 2002-2015, and GNU GPL'd, by Julian Seward et al.
==2541== Using Valgrind-3.11.0 and LibVEX; rerun with -h for copyright info
==2541== Command: sapi/cli/php ext/redis/tests/TestRedis.php --class RedisArray
==2541== Parent PID: 17191
==2541==
==2541== Conditional jump or move depends on uninitialised value(s)
==2541== at 0xB9026F: gc_zval_possible_root (zend_gc.c:149)
==2541== by 0xB4226F: gc_zval_check_possible_root (zend_gc.h:183)
==2541== by 0xB4243F: i_zval_ptr_dtor (zend_execute.h:86)
#!/usr/bin/env bash
{ cat /tmp/this.fails
cat /tmp/this.also.fails # This returns $? == 1
echo "This is executed" # This still gets echoed
} || {
echo "this is not" # this does not
}