Skip to content

Instantly share code, notes, and snippets.

@gkorland
Last active January 18, 2022 20:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gkorland/69c16eae7874f1045c616a1682759e95 to your computer and use it in GitHub Desktop.
Save gkorland/69c16eae7874f1045c616a1682759e95 to your computer and use it in GitHub Desktop.
#### GETEX
import redis
r = redis.Redis()
r.set(“somekey”, “hello”)
r.getex(“somekey”, ex=15)
### >>> returns “Hello”
r.ttl(“somekey”)
### >>> 15
#### CLIENT INFO AND KILL
import redis
r = redis.Redis()
r2 = redis.Redis()
r.client_setname('redis-py-c1')
r2.client_setname('redis-py-c2')
clients = [client for client in r.client_list()
if client.get('name') in ['redis-py-c1', 'redis-py-c2']]
clients_by_name = dict([(client.get('name'), client)
for client in clients])
r.client_kill_filter(laddr=clients_by_name['redis-py-c2'].get('laddr'))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment