Skip to content

Instantly share code, notes, and snippets.

@najathi
Last active September 15, 2022 07:49
Show Gist options
  • Save najathi/50a10a22f85780330e1858a434d64a55 to your computer and use it in GitHub Desktop.
Save najathi/50a10a22f85780330e1858a434d64a55 to your computer and use it in GitHub Desktop.
Redis Configuration
Follow this instractions
1. Install usig WSL (This step only for windows machine)
Windows Subsystem Linux: https://docs.microsoft.com/en-us/windows/wsl/install
2. check distribution
uname
3. install redis
sudo apt-get update
sudo apt-get install redis
4. run redis server
redis-server
5. open new terminal, access the redis cli
redis-cli
1. open new terminal, access the redis cli
redis-cli
Handling with strings - SET / GET
---------------------
SET name najathi
GET name
SET aga 25
get age
# delete
DEL age
# check
EXISTS name
EXISTS age
# list all keys
KEYS *
# flush all keys
flushall
expiration - TTL
-----------------------
# check expiration, -1 means no expiration
ttl name
# make expire 10 seconds
SET name najathi
expire name 10
ttl name
setex name 10 najathi
ttl name
Handling with array - LPUSH / RPUSH
---------------------
# create friends array
lpush friends programming
lpush friends DSA
rpush friends computer
# get
lrange friends 0 -1
# POP
# remove item by FIFO
LPOP friends
# remove item by LILO
RPOP friends
Handling with unique array - SADD
---------------------
# add
SADD hobbies "weight lifting"
# list
SMEMBERS hobbies
# remove
SREM hobbies "weight lifting"
Handling with object - HSET
---------------------
# add
HSET person name najathi
HSET person age 25
# list
HGETALL person
# delete
HDEL person age
#exsists, it returns 1 is true, otherwise false.
HEXISTS person name
HEXISTS person age
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment