-
Notifications
You must be signed in to change notification settings - Fork 0
/
hash_01.py
45 lines (31 loc) · 907 Bytes
/
hash_01.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
import redis
import os
import sys
REDIS_HOST = os.environ[ 'REDIS_HOST' ]
REDIS_PORT = os.environ[ 'REDIS_PORT' ]
#REDIS_DB = os.environ[ 'REDIS_DB' ]
REDIS_DB = 0
REDIS_AUTH = os.environ[ 'REDIS_AUTH' ]
# connect to redis
r = redis.Redis( host = REDIS_HOST
,port = REDIS_PORT
,db = REDIS_DB
,password = REDIS_AUTH
,decode_responses= True
)
# Insert key values in redis
mapping = {
'cat' : 'Patitas',
'dog' : 'Pirana',
'turtle': 'Ninja'
}
r.hset( 'animals', mapping= mapping )
result = r.hgetall( 'animals' )
print( result )
print( 'delete turtle' )
r.hdel( 'animals', 'turtle' )
result = r.hgetall( 'animals' )
print( result )
# ------------------------------------------------------------
# ------------------------------------------------------------
print( '\n\n End \n' )