Skip to main content
edited tags
Link
deleted 1 character in body
Source Link

I am doing a project where I am analyzing a group of Tweets.

What I need to do is find the occurrence of each individual word. I am fairly new to Redis, so I am not quite sure that my solution is optimal. I am storing a key value pair for each word. TheyThe key is a word, and the value is the occurrence count. I then use a list to keep track of every word that goes into the cache.

$cache = new Redis;
$words = array('foo', 'bar', 'baz');

foreach ($words as $word) {
    if ($cache->exists($word) {
        $cache->incr($word);
    } else {
        $cache->put($word, 1);
        $cache->lpush('words', $word);
    }
}

$data = array();
$list = $cache->lrange('words', 0, -1);

foreach ($list as $word) {
    $data[$word] = $cache->get($word);
}

asort($data);

I am doing a project where I am analyzing a group of Tweets.

What I need to do is find the occurrence of each individual word. I am fairly new to Redis, so I am not quite sure that my solution is optimal. I am storing a key value pair for each word. They key is a word, and the value is the occurrence count. I then use a list to keep track of every word that goes into the cache.

$cache = new Redis;
$words = array('foo', 'bar', 'baz');

foreach ($words as $word) {
    if ($cache->exists($word) {
        $cache->incr($word);
    } else {
        $cache->put($word, 1);
        $cache->lpush('words', $word);
    }
}

$data = array();
$list = $cache->lrange('words', 0, -1);

foreach ($list as $word) {
    $data[$word] = $cache->get($word);
}

asort($data);

I am doing a project where I am analyzing a group of Tweets.

What I need to do is find the occurrence of each individual word. I am fairly new to Redis, so I am not quite sure that my solution is optimal. I am storing a key value pair for each word. The key is a word, and the value is the occurrence count. I then use a list to keep track of every word that goes into the cache.

$cache = new Redis;
$words = array('foo', 'bar', 'baz');

foreach ($words as $word) {
    if ($cache->exists($word) {
        $cache->incr($word);
    } else {
        $cache->put($word, 1);
        $cache->lpush('words', $word);
    }
}

$data = array();
$list = $cache->lrange('words', 0, -1);

foreach ($list as $word) {
    $data[$word] = $cache->get($word);
}

asort($data);
Clean up text
Source Link
jsanc623
  • 2.9k
  • 16
  • 22

I am doing a project where i'mI am analyzing a bunchgroup of Tweets.

First thing iWhat I need to do is find the occurrence of each individual word. I'm I am fairly new to Redis, so iI am not quite sure that my waysolution is optimal. I am storing a key value pair for each word, the. They key being theis a word, and the value beingis the occurrence count and. I then i use a list to keep track of every word that goes into the cache.

$cache = new Redis;
$words = array('foo', 'bar', 'baz');

foreach ($words as $word) {
    if ($cache->exists($word) {
        $cache->incr($word);
    } else {
        $cache->put($word, 1);
        $cache->lpush('words', $word);
    }
}

$data = array();
$list = $cache->lrange('words', 0, -1);

foreach ($list as $word) {
    $data[$word] = $cache->get($word);
}

asort($data);

I doing a project where i'm analyzing a bunch of Tweets.

First thing i need to do is find the occurrence of each individual word. I'm fairly new to Redis, so i am not quite sure my way is optimal. I am storing a key value pair for each word, the key being the word and the value being the occurrence count and then i use a list to keep track of every word that goes into the cache.

$cache = new Redis;
$words = array('foo', 'bar', 'baz');

foreach ($words as $word) {
    if ($cache->exists($word) {
        $cache->incr($word);
    } else {
        $cache->put($word, 1);
        $cache->lpush('words', $word);
    }
}

$data = array();
$list = $cache->lrange('words', 0, -1);

foreach ($list as $word) {
    $data[$word] = $cache->get($word);
}

asort($data);

I am doing a project where I am analyzing a group of Tweets.

What I need to do is find the occurrence of each individual word. I am fairly new to Redis, so I am not quite sure that my solution is optimal. I am storing a key value pair for each word. They key is a word, and the value is the occurrence count. I then use a list to keep track of every word that goes into the cache.

$cache = new Redis;
$words = array('foo', 'bar', 'baz');

foreach ($words as $word) {
    if ($cache->exists($word) {
        $cache->incr($word);
    } else {
        $cache->put($word, 1);
        $cache->lpush('words', $word);
    }
}

$data = array();
$list = $cache->lrange('words', 0, -1);

foreach ($list as $word) {
    $data[$word] = $cache->get($word);
}

asort($data);
Source Link
Loading