Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 1.
- Zawartość pliku whatnext.js
- const redis = require('redis');
- const client = redis.createClient();
- client.on("error", (err) => { console.log("Error " + err); });
- var BreakException = {};
- function nextWord(lastWord, currentText) {
- client.zrevrange(`word:${lastWord}:nextwords`, 0, -1, function(err, replies) {
- console.log(`Word ${lastWord}:`)
- var i = 0;
- replies.forEach((reply) => {
- if (i < 5 && reply.startsWith(currentText)) {
- console.log(reply);
- ++i;
- }
- })
- });
- }
- nextWord("greater", "t");
- nextWord("kill", "h");
- nextWord("watson", "s");
- client.quit();
- Wyniki dla parametrów:
- greater, t
- than
- trust
- kill, h
- him
- her
- his
- watson, s
- said
- should
- surely
- so
- shrugged
- 2
- const fs = require('fs'), redis = require('redis');
- function readFile(filename, key) {
- const client = redis.createClient();
- client.on("error", (err) => { console.log("Error " + err); });
- fs.readFile(filename, 'utf8', function(err, data) {
- if (err) {
- return console.log(err);
- }
- var splits = data.split(/\W/).filter(
- (value) => value.length > 1
- ).map(
- (value) => value.toLocaleLowerCase()
- );
- splits.forEach((value, index) => {
- client.sadd(key, value);
- });
- client.quit();
- });
- }
- readFile('cano.txt', 'arthur');
- readFile('t8.shakespeare.txt', 'william');
- 3
- a. William Shakespeare Poprawnie
- 4
- 9792
- 5
- const fs = require('fs'), redis = require('redis');
- function readFile(filename, key) {
- const client = redis.createClient();
- client.on("error", (err) => { console.log("Error " + err); });
- fs.readFile(filename, 'utf8', function(err, data) {
- if (err) {
- return console.log(err);
- }
- var splits = data.split(/\W/).filter(
- (value) => value.length > 1
- ).map(
- (value) => value.toLocaleLowerCase()
- );
- splits.forEach((value, index) => {
- client.zadd(key, 0, value);
- });
- client.quit();
- });
- }
- readFile('cano.txt', 'sorted');
- readFile('t8.shakespeare.txt', 'sorted');
- 6
- 16408
- 7
- alack
- ale porpawna odpowiedź to ponoć
- `antiumz
- antium
- 8
- 23870
- 9
- const fs = require('fs'), redis = require('redis');
- function readSortedList(listKey, sortedListKey, mapKey) {
- const client = redis.createClient();
- client.on("error", (err) => { console.log("Error " + err); });
- client.zrange(sortedListKey, 0, -1, function(err, sortedReplies) {
- if (err)
- throw(err);
- sortedReplies.forEach((value, index) => {
- client.sismember(listKey, value, function(err1, isMember) {
- if (err1)
- throw(err1);
- if (isMember)
- client.setbit(mapKey, index, 1);
- })
- });
- })
- client.bitpos(mapKey, 0, function(err, ret) {
- console.log(ret);
- });
- // client.quit();
- }
- readSortedList('arthur', 'sorted', 'arthur:bitwords');
- 10
- fałsz
- 11
- 0238
- 12
- const redis = require('redis');
- function createHyperLogLog(arthur, william, logKey) {
- const client = redis.createClient();
- client.on("error", (err) => { console.log("Error " + err); });
- client.sinter(arthur, william, function(err, values) {
- if (err)
- throw(err);
- values.forEach((value, index) => {
- client.pfadd(logKey, value);
- })
- });
- }
- createHyperLogLog('arthur', 'william', 'arthur:hyperwords');
- 13
- 53
- 14
- 48,67
- Ale dobra odpowiedź to ponoć
- 5
- 15
- const dbKeys = await client.keysAsync("db:*");
- (. . .)
- type = await client.hgetAsync("db:"+name, "type");
- release = await client.hgetAsync("db:"+name, "current_release");
- score = await client.hgetAsync("db:"+name, "score");
- A szesnastego nie ma
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement