If you do not want to load the script, then below will work as a single command.
127.0.0.1:6379> eval "return redis.call('SET', KEYS[2], redis.call('GET', KEYS[1]))" 2 key1 key2 OK
Please note that key1 must already be set, otherwise you will receive the following error
Lua redis () command arguments must be strings or integers
So check as shown below and set
127.0.0.1:6379> GET key1 (nil) 127.0.0.1:6379> SET key1 hello OK
Now it will work.
If you want to copy the card to another new card key
eval "return redis.call('HMSET', KEYS[2], unpack(redis.call('HGETALL', KEYS[1])))" 2 existingMapKey newMapKey
Another way is that when you insert time, you can insert the value into two keys using MSET.
redis> MSET key1 "Hello" key2 "Hello" "OK" redis> GET key1 "Hello" redis> GET key2 "Hello"
Ofcource this will not solve the problem of copying when the key is already created.
Also note that in redis there is no way for more than one key to refer to the same value object. All of these workarounds will create duplicate value objects. Therefore, if one of the values ββis updated, it will not be reflected in the other value object.
source share