1
00:00:03,300 --> 00:00:08,700
So in this session, we are going to talk about various data lives which are available in Redis  and also

2
00:00:08,700 --> 00:00:14,840
some of the operations which are available to perform by using these different Data Types.

3
00:00:15,050 --> 00:00:15,330
Okay.

4
00:00:15,360 --> 00:00:16,950
So let's begin.

5
00:00:16,950 --> 00:00:24,450
I'm going to connect to Redis by using  Rediscli and if you remember the service is running on Port

6
00:00:24,450 --> 00:00:26,130
6 3 7 0 in this case.

7
00:00:26,850 --> 00:00:29,070
So we need to specify the port explicitly

8
00:00:35,330 --> 00:00:40,920
and now let's begin with String Data Type. So in a String Data Type or a String.

9
00:00:40,920 --> 00:00:47,720
Key Value Pair, usually just write Set Command and we provide the key name and also we provide the  value

10
00:00:47,720 --> 00:00:47,950
name.

11
00:00:48,800 --> 00:00:53,540
So let's say, our key is a product which is Chair

12
00:00:53,720 --> 00:00:59,120
And also we want to set the price as a value for these key type.

13
00:00:59,740 --> 00:01:00,020
Okay.

14
00:01:00,050 --> 00:01:05,720
So typically we run command like Set and then space and then we provide the Key Name then space

15
00:01:05,750 --> 00:01:07,700
and also we provide the Value.

16
00:01:07,700 --> 00:01:15,380
So once you do this, the value has been set, which means that this value or key value pair has been written

17
00:01:15,380 --> 00:01:23,880
to Redis. Now to get the same value back you use Get command  and also you provided the key name.

18
00:01:24,570 --> 00:01:27,700
So if I do Get Chair, I'm going to get the value back.

19
00:01:27,750 --> 00:01:28,490
Okay.

20
00:01:28,560 --> 00:01:33,510
So similarly you can continue performing this option with different key value pairs

21
00:01:36,950 --> 00:01:46,140
and you will get back the response, you know, depending on the key information you want to get back.

22
00:01:46,190 --> 00:01:52,410
Now let's say, if you want to see all the available key types. For that you can use keys and specify the

23
00:01:52,420 --> 00:01:52,990
pattern.

24
00:01:53,120 --> 00:01:54,650
In this case I'm going to give *

25
00:01:54,650 --> 00:01:59,360
So it is going to be me all the keys which are available in Redis.

26
00:01:59,360 --> 00:02:05,600
So right now we see, we only have 2 keys available and now let's say if you want to delete one of the

27
00:02:05,600 --> 00:02:06,020
keys.

28
00:02:07,010 --> 00:02:15,590
So the command to do that is del space followed by the key and if you want to delete multiple keys

29
00:02:15,590 --> 00:02:18,460
you can also specify Multiple Keys.

30
00:02:18,620 --> 00:02:27,650
But in this case let's say, I want to delete just one key. So I write delete   chair and it is giving us

31
00:02:27,650 --> 00:02:30,110
the value of 1, which means the operation is successful.

32
00:02:30,140 --> 00:02:32,420
So one of the Keys has been removed.

33
00:02:32,420 --> 00:02:37,520
Now if I do Keys *  again. This time I see only 1 value which is Table, because chair  has been

34
00:02:37,520 --> 00:02:39,380
removed.

35
00:02:39,380 --> 00:02:44,300
Now let's see whether Redis  is Key Sensitive or not.

36
00:02:44,570 --> 00:02:44,850
Okay.

37
00:02:44,870 --> 00:02:54,000
So I'm setting a value of chair with value 100 and then we'll set value of chair again, but this type

38
00:02:54,000 --> 00:03:02,910
I'll  keep C in capitals and remaining in lowercase and we type the same amount and this time I'm going

39
00:03:02,910 --> 00:03:08,050
to keep everything in uppercase and I'm going to hit enter.

40
00:03:08,070 --> 00:03:11,160
Now let's see how many different keys we have.

41
00:03:11,310 --> 00:03:14,790
Now you see in this case, different keys we have are more.

42
00:03:15,270 --> 00:03:23,870
So basically the point which I wanted to tell you, that Redis is Key Sensitive. So there is a difference

43
00:03:23,870 --> 00:03:32,210
between this chair and the way this  chair  is treated in Redis. So similarly when

44
00:03:32,210 --> 00:03:34,530
you are performing a delete operation.

45
00:03:34,880 --> 00:03:36,070
And if I give

46
00:03:36,860 --> 00:03:43,630
CHAIR in uppercase. it is only going to delete one of the key, which is matching this value.

47
00:03:43,670 --> 00:03:43,930
Okay.

48
00:03:43,940 --> 00:03:50,870
So now if I see keys *,  I'm going to get the remaining values and one of the value, one of the

49
00:03:50,870 --> 00:04:01,710
Key Value, which has been removed is the CHAIR, which was in uppercase.

50
00:04:01,740 --> 00:04:06,960
Now let's say, you have some kind of you know, counter or Sequence ID number, which you want to store

51
00:04:07,020 --> 00:04:13,530
and also with each operation you want to increment the value of that counter. So you can do that by using

52
00:04:13,720 --> 00:04:16,410
String key value pair as well.

53
00:04:16,410 --> 00:04:19,320
So the way you do is, going to be same.

54
00:04:19,470 --> 00:04:27,660
Let me clear the screen first and I'm going to set a counter or it can be a Sequence ID. let's call

55
00:04:27,660 --> 00:04:32,230
it Sequence ID and let's say we start the value with 1

56
00:04:32,940 --> 00:04:33,260
Okay.

57
00:04:33,270 --> 00:04:43,010
Now if I see the current value of Sequence ID, it is set to 1 and now let's say, with each operation

58
00:04:43,010 --> 00:04:47,050
or whenever I query Redis, I want to increment the value by 1.

59
00:04:47,060 --> 00:04:55,370
So for that we have a command, which is called incr,  Increment and also you provide the keys which

60
00:04:55,370 --> 00:04:57,680
you want to increment.

61
00:04:57,680 --> 00:05:03,320
So in the response, we have got value of 2 which means the existing value of Sequence ID was 1 and

62
00:05:03,320 --> 00:05:08,100
now it has incremented it with 2.

63
00:05:08,250 --> 00:05:12,900
And if you run the same operation again.This time you're going to get value of 3, which means again

64
00:05:12,900 --> 00:05:15,530
it has been  incremented by 1

65
00:05:15,680 --> 00:05:15,910
Okay.

66
00:05:15,960 --> 00:05:21,840
So that is the way you can run Increment or Counters or Sequencer.

67
00:05:26,830 --> 00:05:31,960
However, please remember whenever you do get sequence underscore id, you are always going to get the

68
00:05:31,960 --> 00:05:34,530
latest value of sequence ID

69
00:05:34,600 --> 00:05:37,690
Okay so all of these 3 values have not been set.

70
00:05:37,720 --> 00:05:46,390
So each time, this Increment command, it looks for the current value and then it adds it, adds the current

71
00:05:46,390 --> 00:05:50,420
value with 1 and then it writes the same value back to Redis.

72
00:05:50,470 --> 00:05:53,530
That's why you always get the latest Counter Information.

73
00:05:57,440 --> 00:05:58,720
So if we do Key *

74
00:05:58,990 --> 00:06:06,260
total number of  value  which we see are 4. Other way to count the total number of keys or total number of

75
00:06:07,310 --> 00:06:09,680
records whatever you want to say it.

76
00:06:09,830 --> 00:06:12,730
So available in the Redis right now is, using dbsize command.

77
00:06:12,740 --> 00:06:19,490
So if I write dbsize , hit  enter. I get a value of 4, which means right now  Redis is storing total 4

78
00:06:19,520 --> 00:06:19,910
keys

79
00:06:23,700 --> 00:06:23,990
okay.

80
00:06:24,000 --> 00:06:29,680
So right now whatever operations, which we have performed these are based on single key value pair

81
00:06:30,120 --> 00:06:35,250
But let's say we want to increase the performance and we want to write multiple operations in one set

82
00:06:35,760 --> 00:06:36,700
or in one go.

83
00:06:36,750 --> 00:06:41,480
So we can do that. The way to do that is by using mset command.

84
00:06:41,580 --> 00:06:44,000
So mset stands for Multiple Set.

85
00:06:44,010 --> 00:06:53,040
So basically you are setting multiple values in one command. So you can set up different product prices.

86
00:06:53,040 --> 00:06:57,250
So let me set something like this.

87
00:06:57,260 --> 00:07:08,000
And then there is another product. Let's set it to 200 and then we can set another key value pair.

88
00:07:08,550 --> 00:07:12,570
So in this one I am setting actually 3 key value pairs, using mset command.

89
00:07:12,570 --> 00:07:15,380
And once you hit enter, you get a response of

90
00:07:15,390 --> 00:07:15,670
Okay.

91
00:07:15,690 --> 00:07:18,610
Which means, the data has been inserted to Redis.

92
00:07:18,690 --> 00:07:24,680
So if you do Keys *. You see 3 values or 3 items has been added.

93
00:07:24,750 --> 00:07:27,170
So one was Sofa, the other one was TV.

94
00:07:27,180 --> 00:07:33,210
And the third one was Bed. So all the three items has been added and by mistake

95
00:07:33,210 --> 00:07:41,830
Sofa we wrote as Soft, so the same has been operated here. Okay, now let's say when you want to get Multiple

96
00:07:42,670 --> 00:07:43,530
Values.

97
00:07:43,540 --> 00:07:43,800
Okay.

98
00:07:43,810 --> 00:07:50,710
So basically you want to ask Redis to provide the multiple, you know, you are going to request Redis

99
00:07:50,710 --> 00:07:55,080
with multiple keys and you want the values back for all of those keys.

100
00:07:55,090 --> 00:08:03,180
So the way to do that is using, mget command and let's say I want value of chair, I want value of TV,

101
00:08:03,610 --> 00:08:10,320
I want value of latest  sequence ID. So once you hit enter,you are going to get the values of all of

102
00:08:10,320 --> 00:08:12,800
these three items. OK.

103
00:08:12,810 --> 00:08:18,360
So that's a way to perform mset or mget operation.

104
00:08:19,020 --> 00:08:21,330
And this is going to be faster than Set operation.

105
00:08:21,330 --> 00:08:27,510
The reason being is, you are actually requesting multiple items to Redis and Redis  has to perform

106
00:08:27,900 --> 00:08:31,610
this operation and have to respond you back only ones.

107
00:08:31,620 --> 00:08:35,160
So this operation is faster than using Get or Set command.

108
00:08:40,030 --> 00:08:46,030
Now there can be scenario, when you want to see whether a key already exist or not.

109
00:08:46,030 --> 00:08:54,730
So in that kind of scenario, you can use exists command and with exists you need to provide the key name

110
00:08:55,570 --> 00:08:57,430
and also you can provide Multiple Key Name.

111
00:08:57,430 --> 00:09:01,600
So it is going to check whether all of those keys already exist or not.

112
00:09:01,600 --> 00:09:07,300
So let's say before inserting to Redis, I want to see that whether those keys already exist.

113
00:09:07,810 --> 00:09:14,950
So I can do something like exist and then I want to see whether any key with the name sequence_id

114
00:09:14,950 --> 00:09:16,750
exist or not.

115
00:09:17,110 --> 00:09:20,440
So once I hit enter.  I'm going to get value of 1

116
00:09:20,440 --> 00:09:23,410
So here 1 means value already exists.

117
00:09:23,410 --> 00:09:30,280
Now let's say if I do the same with something called counter. So Counter is a key here and we want

118
00:09:30,280 --> 00:09:33,880
to see whether this counter already exists in Redis or not.

119
00:09:33,880 --> 00:09:40,750
So once we hit enter, we are getting a response of 0, which means it doesn't already exist.

120
00:09:49,520 --> 00:09:49,840
Okay.

121
00:09:49,850 --> 00:09:57,280
Let me clear the screen and let's again see the total keys we have available right now. So let's say

122
00:09:57,280 --> 00:10:03,050
you have a scenario in which you want keys to Auto expire. You don't want  keys to be deleting

123
00:10:03,050 --> 00:10:08,900
manually or programmatically. You don't want to write those things. So Redis has a feature which is called

124
00:10:09,010 --> 00:10:12,590
TTL, which is a time to live.

125
00:10:12,590 --> 00:10:16,610
So you can set up TTL for any keys.

126
00:10:18,230 --> 00:10:26,790
Now the way to do that, is so basically when you are using set command, so along with the set command,

127
00:10:26,790 --> 00:10:32,350
you give key value pair. So let's say, it is a color which is Red.

128
00:10:32,730 --> 00:10:40,380
And now you also pass EX, which denotes that you are setting an expiration for this key.

129
00:10:40,380 --> 00:10:46,760
And let's say, here you need to provide the value in seconds. If you want to provide the value in milliseconds,

130
00:10:46,770 --> 00:10:51,840
then you need to use a PX.  If you want to provide value in seconds,

131
00:10:51,840 --> 00:10:55,110
then you want to, or you need to use EX

132
00:10:55,170 --> 00:11:03,850
Now let's say I want this value of Color to be set to Red, only for 60 seconds.

133
00:11:03,980 --> 00:11:04,340
Okay.

134
00:11:04,350 --> 00:11:06,510
So I'm going to write like this.

135
00:11:06,510 --> 00:11:08,980
And once I hit enter,  this value has been written.

136
00:11:09,090 --> 00:11:14,750
And once you do Get color, you are going to get Red back.

137
00:11:14,760 --> 00:11:21,250
But if the same command you try, after 60 seconds, the response which you are going to get is Nil

138
00:11:21,820 --> 00:11:26,350
because what Redis is going to do is, it is going to delete this key after 60 seconds

139
00:11:30,470 --> 00:11:31,660
okay let's check

140
00:11:31,670 --> 00:11:40,850
now, we still have the value. So  the Threshold still has not reached and also the same thing can

141
00:11:40,850 --> 00:11:43,730
be actually done on, done through programmatically.

142
00:11:43,730 --> 00:11:51,530
So you have like Python or using JAVA,  you can write the data along with the Expiration Time.

143
00:12:00,220 --> 00:12:00,770
okay.

144
00:12:00,780 --> 00:12:04,860
Right now if I'm doing Keys * I can see the keys still exist.

145
00:12:04,950 --> 00:12:09,740
So let's wait for some more time and then we will check the value again

146
00:12:16,120 --> 00:12:16,420
okay.

147
00:12:16,420 --> 00:12:23,380
Now if you see, when I type Keys * ,  we do not see Color.

148
00:12:23,950 --> 00:12:31,650
And also if I type Get Color,  we are getting Nil which means,  this key has been expired. Okay.

149
00:12:31,660 --> 00:12:39,450
So that is the way to use or set a key value pair along with a TTL.

150
00:12:39,540 --> 00:12:41,170
So this is very good.

151
00:12:41,490 --> 00:12:47,310
This is used more in the use cases, where you want some value to be existing only for some particular

152
00:12:47,310 --> 00:12:47,750
time.

153
00:12:47,760 --> 00:12:55,770
For example let's say, you you want a user to avail some, you know, benefits or some services ones in last

154
00:12:55,770 --> 00:13:03,050
2 hours. So you can set a value or you can set a status flag which you can set it to expire every 2

155
00:13:03,050 --> 00:13:04,140
hours.

156
00:13:04,330 --> 00:13:04,610
Okay.

157
00:13:04,640 --> 00:13:10,610
So if the same person tries to avail the same service again within 2 hours, then you are going to check

158
00:13:10,610 --> 00:13:12,650
in Redis, that the value still exists.

159
00:13:12,650 --> 00:13:15,830
It means the user has already availed the benefits.

160
00:13:15,830 --> 00:13:21,070
And you are basically programmatically going to return or show the error message to the user.

161
00:13:21,740 --> 00:13:27,670
And if it tries again with after 2 hours, then you should be able to check that the value doesn't exist in Redis

162
00:13:27,690 --> 00:13:36,960
And then the user can be allowed to avail that service again. So similarly there can be another

163
00:13:37,290 --> 00:13:43,710
use cases,  like if you want to check Duplication, Data Duplication or File Duplication, then you can

164
00:13:43,710 --> 00:13:50,860
use the same feature. Let's say, you want to see Duplication only within  last 2 days or 3 days.

165
00:13:51,280 --> 00:14:03,070
So you can use this, this kind of feature where the keys expire after two or three days.

166
00:14:03,130 --> 00:14:09,090
Now let's say there are some existing keys and I want to set the expiration on those key.

167
00:14:09,490 --> 00:14:12,040
So the way to do that is  by using Expire

168
00:14:12,040 --> 00:14:12,580
command.

169
00:14:12,580 --> 00:14:17,160
So you provide Expire and you provide the name of the key.

170
00:14:17,200 --> 00:14:18,850
So in this case we are providing

171
00:14:22,100 --> 00:14:28,460
let's make it Bed and let's provide the total number of seconds. So let's again keep it 60 seconds.

172
00:14:28,460 --> 00:14:34,210
So now this value or this key value pair is going to expire in 60 seconds.

173
00:14:34,250 --> 00:14:44,660
So if I do Get command and I do Get space Bed, I'm going to get the price of Bed but after 60 seconds

174
00:14:44,660 --> 00:14:45,410
if I do the same

175
00:14:45,410 --> 00:14:46,250
command.

176
00:14:46,430 --> 00:14:47,180
It is not,

177
00:14:47,180 --> 00:14:53,030
It is going to give us  response of null or nil, which means the key has been deleted.

178
00:14:53,030 --> 00:14:58,760
Now let's say if there was a scenario, in which we wrongly set the expiration and actually we don't want

179
00:14:58,760 --> 00:14:59,890
the key to expire.

180
00:15:00,530 --> 00:15:02,450
So you can use persist

181
00:15:02,450 --> 00:15:10,460
command and with the persist command you can also provide the Key Name. So i am providing the Key Name.

182
00:15:10,520 --> 00:15:17,390
Now this value you know, whatever expiration  which we had set has been reset and now this value is

183
00:15:17,470 --> 00:15:20,600
or this key value pair is not going to be deleted.

184
00:15:22,960 --> 00:15:23,350
OK.

185
00:15:23,350 --> 00:15:28,480
And now this is going to be basically staying in Redis forever until someone is deleting it manually

186
00:15:29,160 --> 00:15:34,070
or someone is setting expiry on this key.

187
00:15:34,180 --> 00:15:43,700
So if I do Get Bed, I get the value back.

188
00:15:43,930 --> 00:15:44,210
OK.

189
00:15:44,240 --> 00:15:53,920
So these are the, you know,  various options which we have available for strings types. Now let's explore about various

190
00:15:53,920 --> 00:16:04,050
Lists option available in Redis.  So i will clear the screen and let's also do  Flush all.  So Flush all

191
00:16:04,060 --> 00:16:09,140
command is going to delete whatever number of keys which we had in Redis.  it is a destructive

192
00:16:09,140 --> 00:16:09,530
command.

193
00:16:09,530 --> 00:16:14,200
So please use it with care. OK.

194
00:16:14,200 --> 00:16:20,710
So now if I do dbsize, I'm going to get 0, which means we do not have anything stored in Redis right

195
00:16:20,710 --> 00:16:21,300
now.

196
00:16:21,490 --> 00:16:28,030
or if I do keys *, you see we get empty list in response which means we do not have

197
00:16:28,030 --> 00:16:39,800
anything stored in Redis. Now let's begin with, working with Redis lists. So in Redis list you actually

198
00:16:39,800 --> 00:16:49,050
perform Push Operations. So you can insert a value from left side or right side in a list. For the first

199
00:16:49,050 --> 00:16:53,770
time, when you are creating a list, for the first time it doesn't matter whether you use R push command

200
00:16:53,770 --> 00:16:56,310
or L push command. It is going to work the same way.

201
00:16:56,850 --> 00:17:05,590
So let's say I want to write a value or a key value appear to Redis list and my list is called, let's

202
00:17:05,590 --> 00:17:10,590
say Color and it is having different color names.

203
00:17:11,270 --> 00:17:20,750
Let's say we have Red, we have Blue, we have White and once I hit enter, now three values has been inserted

204
00:17:20,750 --> 00:17:28,180
to Redis and once we do  Keys * we can see we have a key which is called Color and if we do,

205
00:17:32,040 --> 00:17:39,350
so if you run  Get command with this key, it is not going to work because when you are actually storing

206
00:17:39,440 --> 00:17:46,670
a key, you need to use L range to get the value back.

207
00:17:46,670 --> 00:17:53,450
So right now we have stored 3 Values and remember Array always starts with 0. So this value is

208
00:17:53,450 --> 00:17:54,470
position 0.

209
00:17:54,490 --> 00:17:56,440
And this value is at position 1

210
00:17:56,480 --> 00:17:59,570
And this Value is  stored at position 2, in an Array

211
00:18:00,770 --> 00:18:07,880
So if I specify L range starting from 0 and let's say I want to see all the values which is available

212
00:18:07,880 --> 00:18:10,990
in or which are stored in this key.

213
00:18:11,150 --> 00:18:17,140
So I need to type L range. Specify the key name. Specify the starting Array  position.

214
00:18:17,210 --> 00:18:22,850
In this case it is going to be 0, because I want to see from beginning and let's say I want to see

215
00:18:22,850 --> 00:18:23,420
everything.

216
00:18:23,420 --> 00:18:24,790
So whatever value which

217
00:18:24,830 --> 00:18:27,560
this list has.  I want to see all the values.

218
00:18:27,560 --> 00:18:30,630
So in that case you specify -1

219
00:18:31,370 --> 00:18:38,880
So what this going to do is, it is going to list all the values which is stored in key, which has a name

220
00:18:38,880 --> 00:18:42,280
of Color. Okay.

221
00:18:42,290 --> 00:18:49,090
Now if you want to see only top 2 values. So you can do starting from 0 until 2.

222
00:18:49,110 --> 00:18:49,400
Okay.

223
00:18:49,410 --> 00:18:55,680
This is giving us 3 values because index, remember index starts from 0 so 0 to 2 is going to give

224
00:18:55,680 --> 00:18:56,430
us 3 values.

225
00:18:56,460 --> 00:19:02,390
So if you want to see top 2, you need to provide from 0 until 1.

226
00:19:02,470 --> 00:19:05,050
So as you see now we are getting only top 2 values

227
00:19:10,550 --> 00:19:12,680
now once again let's see all the values.

228
00:19:12,680 --> 00:19:17,800
And now let's see how the L push or R push operation works.

229
00:19:17,810 --> 00:19:22,490
So when I do L push, values are  going to be inserted at the top.

230
00:19:22,880 --> 00:19:23,180
Okay.

231
00:19:23,210 --> 00:19:31,910
So if I do L push color and I type Black. Okay I want to set the value of black in this color list the

232
00:19:31,910 --> 00:19:37,330
black is going to be inserted at the top because we are inserting the value from the left.

233
00:19:37,850 --> 00:19:48,160
So you can imagine a list which is actually horizontal and left is actually the top side and  right is

234
00:19:48,450 --> 00:19:54,700
at the bottom side.

235
00:19:54,860 --> 00:20:00,490
So once I do this and if I run L range command again.

236
00:20:00,670 --> 00:20:04,870
Now you see we have got the List and Black was inserted at the top.

237
00:20:05,470 --> 00:20:13,280
Okay you are at the top of the list. Now let's say if I use R push and I give a new color, which is let's

238
00:20:13,280 --> 00:20:15,220
say called Magenta.

239
00:20:19,050 --> 00:20:19,460
OK.

240
00:20:19,850 --> 00:20:25,590
So in this case this value is going to be inserted after Red.

241
00:20:25,950 --> 00:20:27,160
Okay.

242
00:20:27,200 --> 00:20:30,320
And also whenever you use L push or R push command,

243
00:20:30,320 --> 00:20:37,790
It tells you the total number of values, which are available in this list. So it has returned us 5

244
00:20:37,800 --> 00:20:45,290
which means current size of list is 5. Now let's run L range again.

245
00:20:45,620 --> 00:20:51,050
And now we see the new value which we had inserted in this list which was Magenta and since we used

246
00:20:51,640 --> 00:20:54,830
R push, this value was inserted at the bottom.

247
00:20:55,070 --> 00:21:04,380
So again depending on the use case, you can use R push or L push and now let's say if I want to always

248
00:21:04,380 --> 00:21:15,320
see top 3 values. I can run, so I just want to see, Yeah, you need to run 0 space 2

249
00:21:15,440 --> 00:21:19,180
So starting index  is 0 in  last index is 2

250
00:21:19,250 --> 00:21:22,040
So it is always going to give you top 3 values

251
00:21:29,390 --> 00:21:35,670
and let's say if you want to know the total length of the List. You can use a Llen command and you need

252
00:21:35,670 --> 00:21:38,510
to provide the key name.In this case key name is Color.

253
00:21:39,690 --> 00:21:45,810
So once I hit enter, I get a value of 5 which means that right now I have 5 values available in this

254
00:21:45,810 --> 00:21:46,200
keys

255
00:21:50,210 --> 00:21:50,610
okay.

256
00:21:50,630 --> 00:21:52,820
So that's about Singular Operation.

257
00:21:52,820 --> 00:21:58,730
Now let's say we want to provide Multiple Key Value Pairs to L push, so you can do that.

258
00:22:04,720 --> 00:22:08,350
so you type L push space key space all the values

259
00:22:13,850 --> 00:22:16,550
so let's say I have Ping, then I have White,

260
00:22:21,480 --> 00:22:23,610
then we have Dark Brown.

261
00:22:23,610 --> 00:22:25,180
So once I hit enter.

262
00:22:25,470 --> 00:22:29,060
Right now the size of the list has changed from 5 to 8.

263
00:22:29,160 --> 00:22:33,540
So we see  total number of elements which are available is 8

264
00:22:33,540 --> 00:22:42,180
And if I do L range color starting from 0 ending with -1, we are going to get  all the values.

265
00:22:55,640 --> 00:22:56,060
okay.

266
00:22:56,060 --> 00:23:01,700
Also please notice since we used L  push command,  so Pink was inserted first.

267
00:23:01,700 --> 00:23:08,640
So our Existing List was until here, until Black and then we inserted Pink.

268
00:23:08,870 --> 00:23:11,310
So that's why Pink  is at position this.

269
00:23:11,390 --> 00:23:15,470
And after that White was inserted and then Dark Brown was inserted.

270
00:23:15,480 --> 00:23:18,410
That's why Dark Brown is, at the top of the list.

271
00:23:26,450 --> 00:23:30,010
And now let's see if you want to remove one of the values.

272
00:23:30,010 --> 00:23:33,940
You can do that as well in Lists

273
00:23:34,030 --> 00:23:37,250
So the way to do that is you use a pop command.

274
00:23:37,270 --> 00:23:44,220
So use L pop to pop a value  from left.

275
00:23:44,270 --> 00:23:44,490
OK.

276
00:23:44,540 --> 00:23:49,720
So if I do L pop and i provide the key. I don't need to provide any value here.

277
00:23:49,730 --> 00:23:54,430
So the only thing is I can either remove the value from left side or right side.

278
00:23:54,680 --> 00:23:58,060
So I'm going to use L pop, to remove the value from left side.

279
00:23:58,220 --> 00:24:01,410
And I'm going to use R pop to remove the value from  right side.

280
00:24:02,120 --> 00:24:08,930
So if we do L pop and provide the name of the key and hit enter.  It is returning as Dark Brown which means,

281
00:24:08,930 --> 00:24:16,430
it has removed Dark Brown from the list and we can verify the same by doing L range Color 0

282
00:24:16,430 --> 00:24:17,840
-1

283
00:24:18,340 --> 00:24:18,630
OK.

284
00:24:18,660 --> 00:24:27,320
We see now List doesn't contain Dark Brown and you can perform this operation multiple times. So each

285
00:24:27,320 --> 00:24:30,830
time it is going to pop out, one of the elements from the left.

286
00:24:30,830 --> 00:24:34,420
So if I do L pop color again, it has removed White.

287
00:24:35,030 --> 00:24:44,590
And if I do  L pop again, it has removed Pink color. So if I do L range color 0 space

288
00:24:44,590 --> 00:24:47,290
-1,  this time we only get 5 items

289
00:24:55,160 --> 00:24:57,290
now R pop is also very similar.

290
00:24:57,920 --> 00:25:03,330
So you use R pop,  you provide the name of the key and you hit enter.

291
00:25:03,410 --> 00:25:10,560
Now in this case you see, we get value of Magenta because that was at the right side of the list and

292
00:25:10,560 --> 00:25:12,640
now this has been removed from the list.

293
00:25:12,750 --> 00:25:19,170
And now if we see the total amount of available values, we see only 4 values and  Magenta has been removed

294
00:25:19,170 --> 00:25:20,880
from the right side of the list

295
00:25:28,560 --> 00:25:30,300
and now let's

296
00:25:30,330 --> 00:25:33,480
put some more values back to this color.

297
00:25:34,260 --> 00:25:36,210
So I'm going to use L push

298
00:25:49,070 --> 00:25:51,130
Okay and let's see the values again

299
00:25:57,160 --> 00:25:57,460
okay.

300
00:25:57,490 --> 00:26:01,540
So actually, I did not specify the name.

301
00:26:01,540 --> 00:26:09,590
So what it has done is, it has assumed Dark Brown as a key and then it has inserted the value of Magenta and Pink

302
00:26:09,610 --> 00:26:11,650
to this list.

303
00:26:11,650 --> 00:26:14,050
So that's not what we wanted.

304
00:26:14,110 --> 00:26:19,640
So the correct way to do that is, L push,  give the name of the key which is Color  in our case

305
00:26:24,590 --> 00:26:27,460
and then specify all the values.

306
00:26:27,470 --> 00:26:29,200
Now you see it has changed to 7

307
00:26:37,080 --> 00:26:39,790
and now we see total we have value of 7.

308
00:26:39,830 --> 00:26:45,920
Now let's say we have a scenario that we always just want to keep you know, only top 3 colors regardless

309
00:26:45,920 --> 00:26:49,360
of whatever the values being inserted.

310
00:26:49,360 --> 00:26:54,450
So for that one you can use Ltrim Command.

311
00:26:54,460 --> 00:27:02,440
So now the way to do, or the Syntax to use that is Ltrim  and you specify the key name of the

312
00:27:02,440 --> 00:27:02,830
list.

313
00:27:02,830 --> 00:27:10,150
So in this case the name of the key is  Color and we specify the starting position which is 0 and we specify

314
00:27:10,150 --> 00:27:11,020
the ending position.

315
00:27:11,020 --> 00:27:18,670
So if you want top 3, you are going to write from 0 until 2 because 0 is the first  item in the

316
00:27:18,670 --> 00:27:19,150
Array

317
00:27:19,240 --> 00:27:21,370
And 2 is the third item in the  Array.

318
00:27:22,450 --> 00:27:28,540
So what this is going to do is, it is going to remove all the values and going to keep only the values

319
00:27:28,540 --> 00:27:30,580
specified by you, in this list.

320
00:27:31,670 --> 00:27:32,020
OK.

321
00:27:32,050 --> 00:27:33,880
So once we hit enter, it says okay.

322
00:27:33,880 --> 00:27:35,740
which means it has performed the operation.

323
00:27:35,740 --> 00:27:40,430
If I do Lrange Color from 0 until -1.

324
00:27:40,540 --> 00:27:47,630
Now we see our list has been reduced with only the top 3 items. OK.

325
00:27:47,670 --> 00:27:55,240
So when you have you use case of you know, keeping only some certain range of items in the list, you can

326
00:27:55,240 --> 00:28:01,500
use Ltrim command.  So it will remove all the values you know, which is outside of that range.

327
00:28:04,510 --> 00:28:11,680
So let's say if you want only items from fifth until tenth,  so you could have set ltrim space color

328
00:28:15,160 --> 00:28:18,720
and since you want fifth item. You need to give index position of 4

329
00:28:19,240 --> 00:28:25,110
And since you want only until tenth item, you have to give  index position of 9. Okay

330
00:28:25,150 --> 00:28:29,890
So that's the  way to get, from fifth item to 10th item

331
00:28:33,960 --> 00:28:34,270
okay.

332
00:28:34,280 --> 00:28:35,330
Let's clear the  screen.

333
00:28:38,240 --> 00:28:39,190
Let's connect

334
00:28:39,200 --> 00:28:48,130
back to Redis cli

335
00:28:48,300 --> 00:28:56,690
Okay now we are going to learn about Hashes. so Hashes are very simple and also in  operations

336
00:28:56,730 --> 00:28:58,930
It is kind of similar to Strings.

337
00:28:58,970 --> 00:29:06,700
So what it does is, you type h set command  to set a value or Key Value Pair.

338
00:29:06,700 --> 00:29:16,360
So rather than usually in use, when you are performing strings data type operations, you are providing

339
00:29:16,360 --> 00:29:17,350
Key and Value Pair.

340
00:29:18,160 --> 00:29:23,860
However, when you are working with  Hashes, you provide a Key and then you also provide a Field Value

341
00:29:23,870 --> 00:29:24,190
Pair.

342
00:29:24,610 --> 00:29:24,880
Okay.

343
00:29:24,900 --> 00:29:29,450
So in this case let's say, we want all the product prices to be stored.

344
00:29:29,650 --> 00:29:32,560
So product is going to be the Key in this case.

345
00:29:32,740 --> 00:29:38,740
And then I need to provide all the Field and Value combination. So let's say, the field which I have

346
00:29:38,740 --> 00:29:42,390
is Chair which is having value of 100 or price of 100

347
00:29:42,460 --> 00:29:47,340
And then we have Table which is having price of 200.

348
00:29:47,560 --> 00:29:49,950
We have TV which is having a price of 300.

349
00:29:50,500 --> 00:29:50,740
Okay.

350
00:29:50,740 --> 00:29:51,970
Something like this.

351
00:29:51,970 --> 00:29:59,530
So once you hit enter, you get a response of 3 which means you have put 3 items or 3 field

352
00:29:59,530 --> 00:30:02,860
values in this  H set. Okay.

353
00:30:02,990 --> 00:30:04,610
Now to get all the items,

354
00:30:11,150 --> 00:30:12,410
you can use H Get

355
00:30:19,420 --> 00:30:24,360
So you provide the name of the key and you provide the field which you want to see.

356
00:30:24,370 --> 00:30:29,760
So in this case if I do Table, I'm going to get a value of 200

357
00:30:34,660 --> 00:30:35,120
okay.

358
00:30:35,140 --> 00:30:39,800
If I do TV, I'm going to get a value of 300.

359
00:30:39,820 --> 00:30:45,520
Now let's say if you want to see all the values. In that case rather than hget, you can use hmget

360
00:30:45,520 --> 00:30:52,930
which is going to give you multiple fields back. So you specify the Key Name,  which is Product in

361
00:30:52,930 --> 00:31:02,840
this case and then you specify all the Field Names. So it is going to be Chair, Table and TV and then you

362
00:31:02,840 --> 00:31:04,620
get 3 values in return.
