0

For a use case, I want to delete a key upon retrieval from Redis server in a single call i.e. key is a one time use. I'm using lettuce library to connect to redis server.

Is there any specific configuration available in redis side or any specific lettuce API I can use? My sample code looks like below.

RedisAsyncCommands<String, String> command = notificationConnection.async();
CompletionStage<String> result = command.get(id)

Lettuce: 5.2.2

Redis: 5.0.8

thanks,

Ashok.

Ashok
  • 461
  • 2
  • 5
  • 23

1 Answers1

4

There is no single command to do it both. Your library may have a method to do it both but redis will receive two commands. If you want it to be atomic you either cover your commands it with multi/exec or use lua script. Here is the example usage of transactions with redis.

127.0.0.1:6379> multi
OK
127.0.0.1:6379> get a
QUEUED
127.0.0.1:6379> del a
QUEUED
127.0.0.1:6379> exec
1) "b" -> result of get
2) (integer) 1 -> result of del
Ersoy
  • 8,816
  • 6
  • 34
  • 48
  • 1
    Thanks @Ersoy. Steps to perform 'multi/exec' using lettuce library is documented at https://github.com/lettuce-io/lettuce-core/wiki/Transactions – Ashok Apr 28 '20 at 13:46
  • @Ashok great and thanks. probably same for each language or library - since they are abstracting redis. – Ersoy Apr 28 '20 at 13:52