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; 
  1. keys1 source key
  2. keys2 target key

the example below uses script load create script , invokes using evalsha passing following arguments:

  1. the sha1 returned script load
  2. a 2 number of keys passed
  3. the source key
  4. 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

Popular posts from this blog

java - Play! framework 2.0: How to display multiple image? -

gmail - Is there any documentation for read-only access to the Google Contacts API? -

php - Controller/JToolBar not working in Joomla 2.5 -