Skip to content

Instantly share code, notes, and snippets.

@itamarhaber
itamarhaber / learn.lua
Created January 10, 2016 15:30 — forked from tylerneylon/learn.lua
Learn Lua quickly with this short yet comprehensive and friendly script. It's written as both an introduction and a quick reference. It's also a valid Lua script so you can verify that the code does what it says, and learn more by modifying and running this script in your Lua interpreter.
-- Two dashes start a one-line comment.
--[[
Adding two ['s and ]'s makes it a
multi-line comment.
--]]
----------------------------------------------------
-- 1. Variables and flow control.
----------------------------------------------------
@itamarhaber
itamarhaber / method-1-binary-file.md
Last active May 16, 2019 17:27
Loading a binary value from a file with redis-cli

Create the file with the actual bytes, not the '\xnn\ representation. For example, in Python:

f = open('filename', 'w')
f.write('\x01\x02\x03')
f.close()

Load the file with redis-cli -x set keyname < filename

@itamarhaber
itamarhaber / code.py
Created November 21, 2015 21:14
Trash Mention's alerts
import requests
import json
jt = json.dumps({'trashed': True})
url = 'https://api.mention.net/api/accounts/<account identifier>/alerts/<alert identifier>/mentions'
gh = {'Accept': 'application/json', 'Accept-Language': 'en', 'Authorization': 'Bearer <token>'}
ph = gh.copy()
ph['Content-Type'] = 'application/json'
foo@bar:~/src/quadtree$ redis-cli zcard x
(integer) 100000
foo@bar:~/src/quadtree$ redis-cli zcard y
(integer) 100000
foo@bar:~/src/quadtree$ redis-cli hlen qt
(integer) 56325
foo@bar:~/src/quadtree$ redis-cli script load "`cat rqtih.lua`"
"84f91fddf261e9a2ef14ff4b417443eed3dc4b2b"
foo@bar:~/src/quadtree$ redis-benchmark -n 100 -r 1000000 evalsha 84f91fddf261e9a2ef14ff4b417443eed3dc4b2b 3 x y tmp zquery __rand_int__ __rand_int__ __rand_int__ __rand_int__
====== evalsha 84f91fddf261e9a2ef14ff4b417443eed3dc4b2b 3 x y tmp zquery __rand_int__ __rand_int__ __rand_int__ __rand_int__ ======
@itamarhaber
itamarhaber / output.txt
Created September 27, 2015 06:54
memtier_benchmark results for Memcached and Redis using the defaults on a i5 laptop in a VM
foo@bar:~/memtier_benchmark$ ./memtier_benchmark -p 11211 -P memcache_text -x 1
[RUN #1] Preparing benchmark client...
[RUN #1] Launching threads now...
[RUN #1 100%, 46 secs] 0 threads: 2000000 ops, 44427 (avg: 43467) ops/sec, 1.27MB/sec (avg: 1.24MB/sec), 4.50 (avg: 4.58) msec latency
4 Threads
50 Connections per thread
10000 Requests per thread
Type Ops/sec Hits/sec Misses/sec Latency KB/sec
------------------------------------------------------------------------
@itamarhaber
itamarhaber / 00_external_references.md
Last active April 25, 2017 18:21
Use Redis in Odd and Unusual Ways - Percona LIVE! Europe 2015

Slidedeck: https://www.slideshare.net/itamarhaber/use-redis-in-odd-and-unusual-ways

  1. Redis Watch - a periodic newsletter about everything Redis: http://bit.ly/RedisWatch
  2. Redis homepage: https://redis.io/
  3. Redis source: https://github.com/antirez/redis
  4. Antirez (a.k.a Salvatore Sanfilippo) - Redis' creator - blog: http://antirez.com/
  5. Redis Labs - the home of Redis: https://redislabs.com
  6. The Redis Manifesto: https://github.com/antirez/redis/blob/unstable/MANIFESTO
  7. Latency Numbers Every Programmer Should Know: https://gist.github.com/jboner/2841832
  8. Programming Languages Benchmark: https://attractivechaos.github.io/plb/
@itamarhaber
itamarhaber / external-references.md
Last active August 13, 2020 19:21
20150903 Ask a Redis Expert Webinar - Why Your MongoDBNeeds Redis
@itamarhaber
itamarhaber / 10-redis-commandments.md
Last active September 25, 2015 08:49
Ten Redis Commandments

creative

"Went up the mountain, spent some time there, a bush or something was burning and I must have inhaled the smoke because I came back down carrying these two slabs of stone...", HippieLogLog

Ten Redis Commandments

I. I am thy open source, BSD licensed, data structure store

II. Thou shalt have no other data but that which fits in RAM

@itamarhaber
itamarhaber / absttl.lua
Created August 5, 2015 21:29
Redis absolute TTL (accuracy +/- 1 second)
-- Returns a key's absolute TTL
local t = tonumber(redis.call('TTL', KEYS[1]))
if t > 0 then
t = t + tonumber(redis.call('TIME')[1])
end
return t
@itamarhaber
itamarhaber / redis rdb ttl
Created July 23, 2015 11:57
What happens to volatile keys when loading from RDB in Redis?
foo@bar:~$ redis-cli
127.0.0.1:6379> flushall
OK
127.0.0.1:6379> save
OK
127.0.0.1:6379> set p persistent
OK
127.0.0.1:6379> set v volatile
OK
127.0.0.1:6379> expire v 99999999