Created
April 29, 2018 22:07
-
-
Save ggarber/c77a0208fd090e8e818ac9ae8ae1ffb6 to your computer and use it in GitHub Desktop.
This file contains 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
import time | |
import redis | |
r = redis.StrictRedis() | |
script_set = r.register_script("local obj = cmsgpack.unpack(redis.call('hget', KEYS[1], ARGV[1]) or ''); if (not obj) then o = {} end; obj[ARGV[2]] = ARGV[3]; return redis.call('hset', KEYS[1], ARGV[1], cmsgpack.pack(obj))") | |
script_get = r.register_script("local obj = cmsgpack.unpack(redis.call('hget', KEYS[1], ARGV[1]) or ''); local res = {}; local n = 0; if (obj) then for k,v in pairs(oboj) do res[n + 1] = k; res[n + 2] = v; n = n + 2; end; end; return res") | |
print(script_set(keys=['user_id'], args=['device1', 'last_online', int(time.time())])) | |
print(script_get(keys=['user_id'], args=['device1'])) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment