Skip to content

Commit

Permalink
Merge pull request #336 from cyhsutw/cyhsutw/update-redis-example
Browse files Browse the repository at this point in the history
Update Redis Example: Fix AttributeError
  • Loading branch information
dan-blanchard authored Nov 16, 2016
2 parents bc49dfd + bd9a52b commit 705a402
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
6 changes: 3 additions & 3 deletions examples/redis/project.clj
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
:target-path "_build"
:min-lein-version "2.0.0"
:jvm-opts ["-client"]
:dependencies [[org.apache.storm/storm-core "1.0.1"]
[org.apache.storm/flux-core "1.0.1"]]
:dependencies [[org.apache.storm/storm-core "1.0.2"]
[org.apache.storm/flux-core "1.0.2"]]
:jar-exclusions [#"log4j\.properties" #"org\.apache\.storm\.(?!flux)" #"trident" #"META-INF" #"meta-inf" #"\.yaml"]
:uberjar-exclusions [#"log4j\.properties" #"org\.apache\.storm\.(?!flux)" #"trident" #"META-INF" #"meta-inf" #"\.yaml"]
)
)
11 changes: 9 additions & 2 deletions examples/redis/src/bolts.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,18 @@ def process(self, tup):
self.emit([word, self.counter[word]])


class RedisWordCountBolt(WordCountBolt):
class RedisWordCountBolt(Bolt):
def initialize(self, conf, ctx):
self.redis = StrictRedis()
self.total = 0

def _increment(self, word, inc_by):
self.total += inc_by
self.redis.zincrby("words", word, inc_by)
return self.redis.zincrby("words", word, inc_by)

def process(self, tup):
word = tup.values[0]
count = self._increment(word, 10 if word == "dog" else 1)
if self.total % 1000 == 0:
self.logger.info("counted %i words", self.total)
self.emit([word, count])

0 comments on commit 705a402

Please sign in to comment.