Skip to content

Instantly share code, notes, and snippets.

@mnunberg
mnunberg / redismodule.h
Created November 22, 2018 12:06
redismodule.h using extern and proper declaration vs. definition separation
#ifndef REDISMODULE_H
#define REDISMODULE_H
#include <sys/types.h>
#include <stdint.h>
#include <stdio.h>
#ifdef __cplusplus
extern "C" {
#endif
@mnunberg
mnunberg / gist:d78c50d3e526d36d5393
Created March 2, 2016 00:11
Subdoc multi packet format
# key: mutateIn_REPLACE_Test
# op[0]: SUBDOC_REPLACE(foo, "car")
# op[1]: SUBDOC_REPLACE(foo, "car")
Operation STORE: Success (Not an error)
performing mutations..
Dumping packet..(kh_span: 45. val: 32
[0]: {0x80 (h)} {128 (d)}
[1]: {0xD1 (h)} {209 (d)}
[2]: {0x0 (h)} {0 (d)}
@mnunberg
mnunberg / gen_stmt_file.py
Last active September 4, 2015 21:16
n1qlback file generator
#!/usr/bin/env python
from argparse import ArgumentParser
import hashlib
import json
import sys
import os
from couchbase.bucket import Bucket
@mnunberg
mnunberg / cmdwrap.h
Created June 9, 2015 16:30
libcouchbase ABI-Safe command wrappers
/*
* Copyright 2015 Couchbase, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
@mnunberg
mnunberg / lcb-cxx-example.cpp
Created April 13, 2015 16:22
C++ libcouchbase API example
#include <libcouchbase/couchbase++.h>
#include <libcouchbase/couchbase++/views.h>
#include <libcouchbase/couchbase++/endure.h>
#include <cassert>
#include <iostream>
#include <vector>
using std::cout;
using std::cerr;
using std::endl;
@mnunberg
mnunberg / n1ql-ryow.c
Last active August 29, 2015 14:18
N1QL read-your-writes with C
/*
* Simple C "script" showing how to connect to Couchbase 4.0 cluster and
* execute a N1QL query. This also creates the primary index which should
* be executed only once.
*
* If you try to run this against an older cluster (e.g. 3.0.x) you will get
* an LCB_NOT_SUPPORTED error (Operation not supported).
*
* Compile and link with couchbase (-lcouchbase). This requires libcouchbase
* version 2.4.8 or greater
@mnunberg
mnunberg / ryow.py
Last active August 29, 2015 14:18
N1QL Read-Your-Writes with Python 2.0
#!/usr/bin/env python
"""
Connect to a Couchbase 4.0 cluster and issue a N1QL query.
Note that primary index creation will fail.
"""
import sys
from time import time
from pprint import pprint
from couchbase.bucket import Bucket
@mnunberg
mnunberg / n1ql-sample.c
Created February 20, 2015 16:53
n1ql/lcb2.4.7
#include <stdlib.h>
#include <stdio.h>
#include <assert.h>
#include <libcouchbase/couchbase.h>
#include <libcouchbase/n1ql.h>
#define CONNSTR "couchbase://localhost:12000/beer-sample"
static void rowCallback(lcb_t instance, int cbtype, const lcb_RESPN1QL *resp) {
if (! (resp->rflags & LCB_RESP_F_FINAL)) {
@mnunberg
mnunberg / beer-sample.c
Created February 19, 2015 21:45
lcb-views-beer-sample
#include <stdlib.h>
#include <stdio.h>
#include <assert.h>
#include <libcouchbase/couchbase.h>
#include <libcouchbase/views.h>
#define CONNSTR "couchbase://localhost:12000/beer-sample"
static void rowCallback(lcb_t instance, int cbtype, const lcb_RESPVIEWQUERY *resp) {
if (! (resp->rflags & LCB_RESP_F_FINAL)) {
@mnunberg
mnunberg / lcb-connmgmt.md
Last active August 29, 2015 14:14
libcouchbase Connection Management

Connection Management in libcouchbase

This document explains how the library handles TCP connections internally. This will cover both HTTP and Memcached connections

Memcached Sockets

Bootstrapping

During initial bootstrap, the library effectively loops over the list of hosts twice,