Wednesday 8 February 2017

Redis Commands with examples

Question: How to set the data with hset?
hset testdata name "Arun Kumar"



Question: How to get the data with hset?
hget testdata name



Question: How to set more data with hset?
hset testdata age "12"
hget testdata age



Question: How to get all data which was set with hset?
hgetall testdata

Output
1) "name"
2) "Arun Kumar"
3) "age"
4) "30"



Question: How to delete data which was set with hset?
hdel testdata age



Question: How to get all data which was set with hset?
hgetall testdata
Command
1) "name"
2) "Arun Kumar"


Redis Commands with examples

Question: How to insert data with lpush ?
lpush usernames "Arun"
lpush usernames "Tarun"
lpush usernames "Karan"



Question: How to list data which was set with lpush ?
lrange usernames 0 10
1)"Arun"
2)"Tarun"
3)"Karan"



Question: How to insert data with zadd?
zadd testdata1 0 "Zero" 
zadd testdata1 1 "One" 
zadd testdata1 2 "Two" 
1) "zero"
2) "ONe"
3) "Two"



Question: Difference between io.sockets.emit and socket.broadcast.emit?
io.sockets.emit will send to all the clients.
socket.broadcast.emit will send the message to all the other clients except the newly created connection.