POST POST

APR
4
2022

Redis Cheat Sheet

ORIGINALLY POSTED TO: https://blog.simontimms.com/2022/04/04/cheat-sheet

Running in Docker

Quickly get started with

1
docker run --name somename -p 6379:6379 redis

Connection

The simplest connection string is to use localhost which just connects to the localhost on port 6379.

Querying

Redis is a really simple server to which you can just telnet (or use the redis-cli) to run commands.

List All Keys

This might not be a great idea against a prod server with lots of keys

1
keys *

Get key type

Redis supports a bunch of different data primatives like a simple key value, a list, a hash, a zset, ... to find the type of a key use type

1
2
type HereForElizabethAnneSlovak
+zset

Set key value

1
set blah 7

This works for updates too

Get key value

1
get blah

Get everything in a zset

1
ZRANGE "id" 0 -1

Count everything in a zset

1
zcount HereForjohnrufuscolginjr. -inf +inf

Get the first thing in a zset

1
ZRANGE "id" 0 0

Get everything in a set

1
SMEMBERS HereFeedHashTags

Get the first member of a list

1
LPOP somekey

Get the last member of a list

1
RPOP somekey

Get the contents of a hash

1
HGETALL somekey

Clear out the whole database

1
FLUSHALL

Clear just the current db

1
FLUSHDB

Simon Timms

Email Email
Web Web
Twitter Twitter
GitHub GitHub
RSS

Looking for someone else?

You can find the rest of the Western Devs Crew here.

© 2015 Western Devs. All Rights Reserved. Design by Karen Chudobiak, Graphic Designer