Last active
          April 19, 2017 20:24 
        
      - 
      
- 
        Save arc279/7a9a74ade926f9b84f4ef0124d7d323b to your computer and use it in GitHub Desktop. 
    redis lua update sample
  
        
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | redis.replicate_commands() | |
| local cr = 0 | |
| local b = {} | |
| while true do | |
| local a = redis.call("SCAN", cr, "MATCH", "????", "COUNT", 10) | |
| for i, v in ipairs(a[2]) do | |
| local j = cjson.encode({v, v, v}) | |
| redis.call("SET", v, j) | |
| b[v] = j | |
| end | |
| cr = a[1] | |
| if cr == "0" then | |
| break | |
| end | |
| end | |
| return cjson.encode(b) | |
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | function redis_bulk() { | |
| printf "*%d\r\n" "${#@}" | |
| for x in "${@}"; do | |
| printf "$%d\r\n%s\r\n" $(gecho -ne "$x" | wc -c) "$x" | |
| done | |
| } | |
| for x in {1..100}; do | |
| redis_bulk SET "$(printf "%04d" $x)" hoge$x | |
| done | redis-cli --pipe | |
| redis-cli --eval a.lua | jq . | |
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment