Quick start with Redis

Ankit Kumar Gupta
2 min readDec 6, 2018

A quick introduction to redis, its a Cache!. Redis is an open source, a key-value store. It is often referred to as a data structure server, since the keys can contain strings, hashes, lists, sets and sorted sets. Redis is written in C.

Below commands are pretty simple and straight forward to get an idea of how redis works.

Install Redis on mac with HomeBrew brew install redis

Uninstall Redis and its files

brew uninstall redis
rm ~/Library/LaunchAgents/homebrew.mxcl.redis.plist
rm /usr/local/etc/redis.conf

Start server redis-server /usr/local/etc/redis.conf

Start Redis server via “launchctl”

launchctl load ~/Library/LaunchAgents/homebrew.mxcl.redis.plist

Stop Redis server redis-cli shutdown

Test if Redis server is running redis-cli ping

Update redis brew update; brew upgrade redis

Working with redis command line

start redis cli redis-cli

// Redis data commands// Strings
SET name "tutorialspoint" // set a string with key
GET name // get value for key
DEL name // delete key
SETEX foo 60 "Hello" // set key foo with TTL of 60 seconds
TTL foo // get TTL for key
// Hashes
HMSET user:1 username tutorialspoint password tutorialspoint points 200
HGETALL user:1
// Lists
lpush tutoriallist item1
lpush tutoriallist item2
lrange tutoriallist 0 10
// Sets
sadd tutoriallist item1
sadd tutoriallist item2
smembers tutoriallist
// Delete everything on redis cache
flushall

Publish / Subscribe channel on redis

Redis also supports pipelining, want to create a broadcasting system, its quick to create that

SUBSCRIBE redisChat
PUBLISH redisChat "broadcast message"

Start Integrating with clients here

--

--