-
Notifications
You must be signed in to change notification settings - Fork 0
/
redis_commands.properties
118 lines (79 loc) · 1.93 KB
/
redis_commands.properties
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
#start redis server on docker
docker run -d -p 6379:6379 --name my-redis redis
#start redis cli client
docker exec -it my-redis sh
redis-cli
#to monitor all the commands
redis-cli monitor
#set a key and value
replaces any exising key of value bar
set bar 100
get bar
#ttl for 5 seconds
ttl bar 5
#to retrieve all the keys
keys *
#to delete a key
del name
#to delete all keys
flushall
#set expiry
setex name 5 dc
ttl name
#checks if a key is available or not. if exists it does not override
setnx hello world
#set multiple values in a single command
mset name1 dc name2 gayathri name3 mugund name4 shrisha
#increment, decrement value
incr num1
decr num1
incrby num1 5
decrby num1 5
#append value
set name hello
append name " world"
get name - > hello world
#Hashes---------------------------------------
hmset student name mugund clas N2
#to retrieve only the specific fields from the key "student"
hget student class
#to retrieve all the fields from key "student"
hgetall student
#to check if a field exists
hexists student surname
#to delete a specific field
hdel student class
#to get all keys in student
hkeys students
#Lists------------------------------------------------
#push items on top of the list
lpush num 1 2 3 4
#to retrieve the range of values from list
lrange num 0 10
#to popout elements from the top
lpop num
#push items on bottom of the list
rpush num 5
#length of the list
llen num
#Sets------------------------------------------------
#add element to set
sadd name 1 2 3 4
#retrieve from set
smembers name
#find number of elements in set
scard name
#subtract myset1 from myset2
sdiff myset2 myset1
#Sorted Sets------------------------------------------------
#adding element to sorted set
zadd myset 1 a 2 b 3 c
#retrieve value using range
zrange myset 0 -1
#pubSub
#subscriber
subscribe my_channel
-subscribe based on pattern. Channels starting with r
psubscribe r*
#publisher
publish my-channel "hello world"