Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F91568518
redis.py
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Subscribers
None
File Metadata
Details
File Info
Storage
Attached
Created
Tue, Nov 12, 07:09
Size
1 KB
Mime Type
text/x-python
Expires
Thu, Nov 14, 07:09 (2 d)
Engine
blob
Format
Raw Data
Handle
22284417
Attached To
R3600 invenio-infoscience
redis.py
View Options
from
invenio.config
import
CFG_REDIS_HOSTS
if
CFG_REDIS_HOSTS
:
from
nydus.db
import
create_cluster
from
invenio.config
import
CFG_REDIS_HOSTS
_REDIS_CONN
=
{}
class
DummyRedisClient
(
object
):
def
get
(
self
,
key
):
pass
def
set
(
self
,
key
,
value
,
timeout
=
None
):
pass
def
delete
(
self
,
key
):
pass
def
get_redis
(
redis_namespace
=
'default'
):
"""Connects to a redis using nydus
We simlulate a redis cluster by connecting to several redis servers
in the background and using a consistent hashing ring to choose which
server stores the data.
Returns a redis object that can be used like a regular redis object
see http://redis.io/
"""
if
not
CFG_REDIS_HOSTS
or
not
CFG_REDIS_HOSTS
[
redis_namespace
]:
return
DummyRedisClient
()
redis
=
_REDIS_CONN
.
get
(
redis_namespace
,
None
)
if
redis
:
return
redis
hosts_dict
=
{}
for
server_num
,
server_info
in
enumerate
(
CFG_REDIS_HOSTS
[
redis_namespace
]):
hosts_dict
[
server_num
]
=
server_info
redis
=
create_cluster
({
'backend'
:
'nydus.db.backends.redis.Redis'
,
'router'
:
'nydus.db.routers.keyvalue.ConsistentHashingRouter'
,
'hosts'
:
hosts_dict
})
_REDIS_CONN
[
redis_namespace
]
=
redis
return
redis
Event Timeline
Log In to Comment