本文整理匯總了Python中redis.client.Redis.get方法的典型用法代碼示例。如果您正苦於以下問題:Python Redis.get方法的具體用法?Python Redis.get怎麽用?Python Redis.get使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類redis.client.Redis
的用法示例。
在下文中一共展示了Redis.get方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: uget
# 需要導入模塊: from redis.client import Redis [as 別名]
# 或者: from redis.client.Redis import get [as 別名]
def uget(self, name):
"""
Return the value and key ``name`` or None, and decode it if not None.
"""
value = Redis.get(self, name)
if value:
return value.decode(self.encoding)
return value
示例2: TSStore
# 需要導入模塊: from redis.client import Redis [as 別名]
# 或者: from redis.client.Redis import get [as 別名]
class TSStore(object):
def __init__(self, config):
self._redis = Redis(host=config.get('redis','host'),
port=int(config.get('redis','port')),
db=int(config.get('redis','db')))
self._delta_secs = int(eval(config.get('timeseries',
'delta_secs')))
self._expiration_delay_secs = int(eval(config.get('timeseries',
'expiration_delay_secs')))
def queries_key(self):
return 'queries'
@property
def queries(self):
return self._redis.smembers(self.queries_key())
@queries.setter
def queries(self, values):
pipe = self._redis.pipeline()
pipe.delete(self.queries_key())
for v in values:
pipe.sadd(self.queries_key(),
v)
return pipe.execute()
def _interval_key(self, timestamp):
return int(timestamp) - int(timestamp) % self._delta_secs
def _ts_key(self, timestamp, query):
return 'ts:%(query)s:%(timestamp_key)s'%{'query':query,
'timestamp_key':self._interval_key(timestamp)}
def _tweet_key(self, t):
if type(t) == Tweet:
return 'tweet:%s'%t.id
return 'tweet:%s'%t
def _query_key(self, query):
return 'query:%s:last_tweet_id'%query
def _store_tweet(self, pipe, tweet):
tweet_key = self._tweet_key(tweet)
pipe.set(tweet_key, tweet.serialize())
pipe.expire(tweet_key, self._expiration_delay_secs)
def _reference_tweet(self, pipe, timestamp, query, tweet):
ts_key = self._ts_key(timestamp, query)
pipe.lpush(ts_key,tweet.id)
pipe.expire(ts_key,self._expiration_delay_secs)
def _update_last_query_tweet(self, pipe, query, tweet):
query_key = self._query_key(query)
pipe.set(query_key,tweet.id)
def append(self, query, tweet):
pipe = self._redis.pipeline()
timestamp = time.time()
self._store_tweet(pipe, tweet)
self._reference_tweet(pipe, timestamp, query, tweet)
self._update_last_query_tweet(pipe, query, tweet)
return pipe.execute()
def retrieve_ts(self, query, timestamp, n_elements=-1):
ts_key = self._ts_key(timestamp, query)
return self._redis.lrange(ts_key, 0, n_elements)
def retrieve_last_tweet_id(self, query):
query_key = self._query_key(query)
return self._redis.get(query_key)
def retrieve_tweet(self, tweet_id):
tweet_key = self._tweet_key(tweet_id)
data = self._redis.get(tweet_key)
return Tweet.deserialize(data).todict()
def retrieve(self, query, n_periods=30):
current_timestamp = now = int(time.time())
start_timestamp = now - self._delta_secs * n_periods
tweets = []
while current_timestamp > start_timestamp:
current_tweet_ids = self.retrieve_ts(query, current_timestamp)
tweets.append({'timestamp': current_timestamp,
'tweets' : [ self.retrieve_tweet(tid) for tid in current_tweet_ids ] })
current_timestamp -= self._delta_secs
return { 'now' : now,
'ts' : tweets }
示例3: Redis
# 需要導入模塊: from redis.client import Redis [as 別名]
# 或者: from redis.client.Redis import get [as 別名]
# -*- coding: utf-8 -*-
__author__ = 'fjs'
from connection import BlockingConnectionPool
from redis.client import Redis
client = Redis(connection_pool=BlockingConnectionPool(max_connections=2))
client.set("fjs", "fjs")
print client.get("fjs")
client.lpush("nn", 1)
print client.lpop("nn")