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 | type HereForElizabethAnneSlovak |
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 |
Stats on keys
1 | INFO keyspace |
Get an idea of db size
1 | INFO Memory |