Spamer & Redis
Hey Redis, ever thought about stuffing a whole pile of jokes into a hash so I can pull one out in a flash for a prank? I need a quick, reliable stash—think of it as a joke cache. Want to help me set it up?
Sure thing. Just treat the jokes like key/value pairs in a hash.
Create a key, say `jokes`, and add each joke with an id or a short label.
```
HSET jokes 1 "Why did the chicken cross the road? To get to the other side."
HSET jokes 2 "I told my computer I needed a break, and it said it needed a cache."
HSET jokes 3 "Why do programmers prefer dark mode? Because light attracts bugs."
```
Now you can pull a random one with:
```
LRANDJOKE=$(HGET jokes $((RANDOM % 3 + 1)))
echo $LRANDJOKE
```
Or if you want a truly random pick each time, you can store the ids in a list and `LRANGE`:
```
LPUSH joke_ids 1 2 3
# Pick a random id
randid=$(LRANGE joke_ids $((RANDOM % 3)) $((RANDOM % 3)))
HGET jokes $randid
```
That gives you a quick, reliable stash of jokes you can fetch in a flash. If you need to add more, just keep pushing to the hash and list. Happy pranking.
Nice! Now the jokes are on standby, ready for an instant laugh drop. If you want a truly random, just pop one with `HGET jokes $(HVALS jokes | shuf -n1)` and keep the chaos rolling. Need more punchlines or a new prank idea? I’m all ears!
Sounds solid. If you need more, just add another key/value pair and bump the id. For a new prank idea, how about a command that returns a random motivational quote every time someone pings the server? It’s like a pep‑talk bot—keeps people guessing if they’re getting a joke or a life lesson. Or you could set up a key that toggles between a joke and a warning when you hit a certain threshold of requests. Keeps the chaos subtle but effective. Let me know if you want the script for it.
That sounds hilarious! Hit me with the script—let’s make the server a daily dose of surprise pep talks and prank warnings. I can’t wait to see people jump when the jokes sneak in!
Here’s a small Lua script you can register in Redis and call with a single command.
It picks a random entry from the `jokes` hash, a random quote from the `quotes` hash, and a random warning from the `warnings` list, then returns a formatted message.
Add the script, then just call it.
```bash
# Save this as prank.lua
return {
"Message:",
cjson.encode{
joke = KEYS[1] and redis.call('HGET', KEYS[1], redis.call('RANDOMKEY', KEYS[1])) or nil,
quote = KEYS[2] and redis.call('HGET', KEYS[2], redis.call('RANDOMKEY', KEYS[2])) or nil,
warning= KEYS[3] and redis.call('LPOP', KEYS[3]) or nil
}
}
```
Register the script:
```bash
redis-cli SCRIPT LOAD "$(cat prank.lua)"
```
The return value is a key `prank` you can call:
```bash
redis-cli EVALSHA <sha> 3 jokes quotes warnings
```
Where `<sha>` is the SHA returned from the LOAD command.
Every time you run it, you get a different combination: a joke, a pep‑talk quote, and a warning that’ll make them jump.
If you want the warning to cycle instead of popping, replace `LPOP` with `LINDEX` and increment an index stored in a separate key.
Enjoy the chaos.