Reputation: 4417
I am storing some values in redis
like for key: 1
the value will be
{"counter":1,"counter1":2}
Now I need to reset value of counter
while the counter1
should be remaining same.
To increase counter I am use the command SETEX mykey 60 redis
.
But it will also reset the value of counter1
. So is there any way I can reset one value for a single key.
Let me know if I need to add some more info.
Upvotes: 0
Views: 1237
Reputation: 9586
Instead of string
you may use hash
, then it will be easy. you can increment
by some other value, delete
counter etc etc. Each key in your json will be hash field
.
127.0.0.1:6379> hset mykey counter 1 counter1 2
(integer) 2
127.0.0.1:6379> hgetall mykey
1) "counter"
2) "1"
3) "counter1"
4) "2"
127.0.0.1:6379> hset mykey counter 25
(integer) 0
127.0.0.1:6379> hgetall mykey
1) "counter"
2) "25"
3) "counter1"
4) "2"
127.0.0.1:6379> HINCRBY mykey counter 15
(integer) 40
127.0.0.1:6379> hgetall mykey
1) "counter"
2) "40"
3) "counter1"
4) "2"
127.0.0.1:6379>
Upvotes: 2