Skip to content

Instantly share code, notes, and snippets.

@itamarhaber
itamarhaber / redis_suffix_index.lua
Created May 23, 2014 15:41
Redis suffix index function in Lua. Call with key name of the search terms set and argument to index
redis.call("zadd", KEYS[1], 1, ARGV[1]:reverse())
@itamarhaber
itamarhaber / index.html
Last active March 29, 2019 02:26
Red is Beautiful: A Visualization of Redis Commands
<!DOCTYPE html>
<!--
Red is Beautiful: A Visualization of Redis Commands
By Itamar Haber, Redis Labs
Adopted from Mike Bostock's Zoomable Pack Layout example: http://mbostock.github.io/d3/talk/20111116/pack-hierarchy.html
!-->
<html>
<head>
<style>
@itamarhaber
itamarhaber / 00 Turbo Boost WordPress with a Secure Memcached Plugin
Last active August 29, 2015 14:04
Snippets accompanying Turbo Boost WordPress with a Secure Memcached Plugin blog post (http://redislabs.com/blog/turbo-boost-wordpress-with-a-secure-memcached-plugin)
Follow these steps to deploy WordPress, Memcached Cloud and the Memcached Cloud Plugin for Wordpress on Heroku.
@itamarhaber
itamarhaber / statsC50-T-1-pipe-75-D-100-Client1-Test3.txt
Created August 22, 2014 03:28
Unbenchmarking Redis on an EC2 instance
1 Threads
50 Connections per thread
1000000 Requests per thread
Type Ops/sec Hits/sec Misses/sec Latency KB/sec
------------------------------------------------------------------------
Sets 198412.70 --- --- 9.04900 28440.00
Gets 198412.70 198412.70 0.00 9.01200 27471.00
Totals 396825.40 198412.70 0.00 9.03000 22623.00
@itamarhaber
itamarhaber / 00-rld-start.lua
Last active April 19, 2017 20:28
Snippets accompanying Redis Lua Debugger blog post
rld.start()
@itamarhaber
itamarhaber / 00_copy_key.lua
Last active December 14, 2023 14:14
The fastest, type-agnostic way to copy a Redis key, as discussed in https://redislabs.com/blog/the-7th-principle-of-redis-we-optimize-for-joy
-- @desc: The fastest, type-agnostic way to copy a Redis key
-- @usage: redis-cli --eval copy_key.lua <source> <dest> , [NX]
local s = KEYS[1]
local d = KEYS[2]
if redis.call("EXISTS", d) == 1 then
if type(ARGV[1]) == "string" and ARGV[1]:upper() == "NX" then
return nil
else
javascript:{function replaceTokens(e,t){var n=e;for(var r in t){n=n.replace(RegExp("[$]"+r,"g"),t[r])}return n}function copyTweetForOverheard(){var e=$(".js-original-tweet");var t={fullname:$(".fullname.js-action-profile-name.show-popup-with-id",e).text(),username:$(".username",e).text(),text:$(".tweet-text",e).text(),url:window.location.href};var n='\t\t\t\t<p style="margin-top: 8px; margin-bottom: 36px;"><strong style="color: rgb(42, 130, 223); text-decoration: none;"><a href="$url" style="color: rgb(42, 130, 223); text-decoration: none;" target="_blank">$fullname $username:</a></strong>&nbsp;&quot;$text&quot;</p>';alert(replaceTokens(n,t))}copyTweetForOverheard()}
@itamarhaber
itamarhaber / redis-watch-trivia-archive.md
Last active December 3, 2015 15:18
Redis Watch Trivia "Facts" - a Meta Archive

Redis Watch Trivia "Facts"

a Meta Archive

Look for a new #RedisTrivia fact every Thursday with your Redis Watch newsletter :)

Lifted with permission from the Redis Watch Archive: https://redislabs.com/redis-watch-archive

  1. Redis stands for REmote DIctionary Server
  2. everybody knows that Redis' default port is 6379, but have you ever wondered why? The answer is that 6379 spells MERZ on the phone's keypad (want to know what MERZ is? Read the appendix at http://oldblog.antirez.com/post/redis-as-LRU-cache.html [warning: slightly NSFW links inside])
@itamarhaber
itamarhaber / main.py
Created February 18, 2015 03:42
Benchmark different pre-ordered sorted sets insertion times to win the bounty at http://stackoverflow.com/questions/28499034/most-efficient-way-to-insert-an-already-sorted-set-into-redis
import redis
import random
import timeit
key = 'so_bounty'
number = 100
sample = 10000
r = redis.Redis()
@itamarhaber
itamarhaber / 99-misc
Last active August 29, 2015 14:19
Redis commands evolution
# get Redis' repo tags and their dates
git log --tags --simplify-by-decoration --pretty="format:%ct %d" | awk 'BEGIN { print "timestamp, tag" } /.*\(.*\)/ { print $1 ", " substr($3, 0, length($3)-1) }' > tags.csv
git log --tags --simplify-by-decoration --pretty="format:%ct %d" | awk 'BEGIN { print "{ \"releases\": [" } /.*\(.*\)/ { print " { \"timestamp\": " $1 ", \"name\": \"" substr($3, 0, length($3)-1) "\" }," } END { print " { \"timestamp\": 0, \"name\": \"the-big-bang\" }"; print "]}" }' > tags.json