database - Redis : How to set one key equal to the value of another key? -
is there quick command in redis allows me following
i want set value of key y equal value of key x .
how go doing redis client .
i use standard redis-cli client .
basically looking equivalent of following -
y.val() = x.val()
you can lua script:
redis.call('set', keys[2], redis.call('get', keys[1])); return 1; - keys1 source key
- keys2 target key
the example below uses script load create script , invokes using evalsha passing following arguments:
- the sha1 returned script load
- a 2 number of keys passed
- the source key
- the target key.
output:
redis 127.0.0.1:6379> set src.key xxx ok redis 127.0.0.1:6379> src.key "xxx" redis 127.0.0.1:6379> script load "redis.call('set', keys[2], redis.call('get', keys[1])); return 1;" "1119c244463dce1ac3a19cdd4fda744e15e02cab" redis 127.0.0.1:6379> evalsha 1119c244463dce1ac3a19cdd4fda744e15e02cab 2 src.key target.key (integer) 1 redis 127.0.0.1:6379> target.key "xxx" it appear lot of stuff compared doing , s set, once you've loaded script (and memorized sha1) can reuse repeatedly.
Comments
Post a Comment