storage icon indicating copy to clipboard operation
storage copied to clipboard

[FEATURE] - Add functions: incr, incrBy, incrByFloat

Open sujit-baniya opened this issue 3 years ago • 9 comments

Along with Set and Get it's better introduce some more functions for data integrity and most of the databases already support above functions.

Some functions:

  1. incr
  2. incrBy
  3. incrByFloat
  4. expire

sujit-baniya avatar Jun 21 '21 07:06 sujit-baniya

@ReneWerner87 @hi019 what do you think about that? I think 1, 2, 3. options would be great.

efectn avatar Mar 09 '22 19:03 efectn

Well I'm not that excited, for me these are just key value storages and more than fetch or set is not needed from my point of view.

But that's just my opinion and I like to be overvote or convinced

ReneWerner87 avatar Mar 09 '22 19:03 ReneWerner87

Oh, I came because I needed an INCR... It is shocking to see that the issue was a year and three months ago.

It seems inevitable that I will have to open two REDIS sessions.

YankeeTube avatar Sep 08 '22 15:09 YankeeTube

Oh, I came because I needed an INCR... It is shocking to see that the issue was a year and three months ago.

It seems inevitable that I will have to open two REDIS sessions.

You can use https://github.com/gofiber/storage/blob/main/redis/redis.go#L104

efectn avatar Sep 08 '22 15:09 efectn

@efectn Thanks

YankeeTube avatar Sep 09 '22 14:09 YankeeTube

access to the db connection is introduced in #451

ReneWerner87 avatar Sep 09 '22 14:09 ReneWerner87

@sujit-baniya do we still need the feature, can you give specific examples of how to use it and when to use it

i think the important thing is that we have now allowed the initalized connection to be used again

ReneWerner87 avatar Sep 09 '22 14:09 ReneWerner87

@ReneWerner87 Yes I think these features: incr, incrBy and incrByFloat will serve high purpose of usability. It's true that for Redis storage we could use Conn() function to get client connection to do stuffs. I purpose to implement these features in all drivers

But since we have Storage interface, most of the developers will use the interface instead of specific driver. That's why I purpose to add these features in interface.

Some of the use cases

  1. Manage the metrics by increasing the value on key
  2. Managing item counter in queues

sujit-baniya avatar Sep 09 '22 15:09 sujit-baniya

For e.g.

I'm building SMS Application and it requires to update SMS counts per user. I plan to use gofiber/storage. Since it supports multiple driver, I could easily switch to any drivers I wanted. And if I've mentioned features in gofiber/storage interface, I would not need to create connections again per driver (it will create a lot mess then)

sujit-baniya avatar Sep 09 '22 15:09 sujit-baniya

@sujit-baniya PR #451 now allows you to get the Conn from any of the storage drivers, not just Redis. Does that help?

gaby avatar Dec 13 '22 02:12 gaby

@gaby That would help a lot. Thanks :)

sujit-baniya avatar Dec 13 '22 04:12 sujit-baniya

@sujit-baniya Let me know if this can be closed :-) Thanks!

gaby avatar Dec 13 '22 04:12 gaby