« first day (2257 days earlier)      last day (2913 days later) » 

00:00
if it's an object, and you're updating single fields at a time, then you should probably use a hash field
yeah, i wouldn't do that then
@Meredith ^
Ok I saw that
i'd store things in better data types
like your player list should be an actual list
or a set
or a sorted set, depending on how you want to use it
00:01
Ok
So this might be a dumb question but remember that I've only ever used sql
or just make it a key if you will always have the player's ID for getting
But how do I relate it to the game's id
I was planning on storing an object, where the keys are game ids
Store the game id as the key for the JSON data
the keys you use in redis are important
So I'd do like game[id].players
00:02
You could do a key like game:<gameid>:players:<playerid>
if you're only ever going to query it when you have those 2 ids
Weird
and if you wanted like... an 'index' equivalent then you can do game:<gameid>:players as a list
You can get fancy and use async await with bluebird too
Ok so my values can pretty much only be hashes/lists/sets/primitives?
getting your head around using dynamic keys is hard, but it's where a lot of the power of redis comes in
00:04
@Meredith the values can be whatever iirc
@Meredith redis gives you a lot of freedom to do whatever you want
Do you typically have nested values?
For keys no
If I don't need to do anything special with the nested values then sure
e.g. a list of hashes, and each hash has a list of hashes
00:05
But you can use the keys function to iterate the redis keys for what you want
but if i wanted to have a list of players that i could add to/remove from then i would store that as a list
you shouldn't really use KEYS
let keysAsync = Promise.promisify(client.keys, {context: client});
const games = await keysAsync("*game*");
yeah, don't do that
I prefix my keys with an identifier so I can regex and sort easier
waaaaat
I'm really glad I asked about this
Ok so if I want a list of players, then I want to get each player's health
I'd access ${gameid}:players (which is a list)
Then ${playerid}:health for each player
00:08
yeah, taht would be one way
Or ${gameid}:${playerid}:health I guess
Grab the key, then map it to access the json data inside, and you'll get your properties
@SterlingArcher re-write in react
do it
do it now
lol I'd be better off rewriting in angular
But react would be fun
and you learn react
so win/win
00:09
Ok next question
How do you generate ids?
@Meredith you can also do MGET redis.io/commands/mget to get several keys at once
Should I just use uuids or is there a way to autoincrement
I like using UUIDs, but they're probably overkill
const generateID = function() {
  return 42 & Date.now()
}
Nah I'm totally cool with overkill
00:10
I use a uuid function
function uuid() {
	let d = new Date().getTime();
	let uuid = 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) {
		let r = (d + Math.random()*16)%16 | 0;
		d = Math.floor(d/16);
		return (c=='x' ? r : (r&0x3|0x8)).toString(16);
	});
	return uuid;
}
I use a node module
Found that somewhere on stack. I'm sure there's an npm module to generate uuids
I use something that i have to call .v4() on
Yeah
That's what I use
You can do const uuid = require('uuid/v4'); though
Then you just uuid()
y u no es6
00:12
Basically what i'd suggest is reading through the redis docs and learning all the data structures and what they're good at.
Cuz you gotta babel to use import/export
import {uuid} from 'uuid/v4';
That's a paid
and then pick whichever structure is best for how you want to query/update your data
pain
00:13
In the homely words of @ndugger that made me babel...
@SterlingArcher y u destructure?
@Meredith BABEEELLLLLLLL
Do I have to worry about whatever the redis equivalent of sql injection is?
> The Redis protocol has no concept of string escaping, so injection is impossible under normal circumstances using a normal client library. The protocol uses prefixed-length strings and is completely binary safe.
Lua scripts executed by the EVAL and EVALSHA commands follow the same rules, and thus those commands are also safe.
While it would be a very strange use case, the application should avoid composing the body of the Lua script using strings obtained from untrusted sources.
I don't think so...
00:14
Sweet
I love redis
if you're using the library to make your calls then you never actually build up strings
but
if you start going crazy and making dynamic LUA functions to run
then yeah you need to be really careful
because redis doesn't have any innate security
oh god lol running redis from process.exec?
no?
what do you mean lua functions then
Is it possible to _.sortBy() when the variable is a string? "sort": "1"
00:19
you can write lua and run that against a redis server
@jbolanos you're going to have to explain that better... you want to sort a single string?
I need to sort json objects by a single key/value "Sort": "1" but the value is a string instead of an int which means it sorts as boolean
is there a way to convert it to an int during/before the sort?
oh
parseInt?
I tried return Number(t.Sort); but that didn't work
parseInt(t.Sort, 10)?
6
A: Is it possible to run a string injection attack on a redis query?

Sven HerzbergThere is a small attack vector for these kinds of string injections. While the redis documentation is clear about the difficulty of executing multiple commands on the database, it does not mention that the key separator (':' in your example) usually needs to be escaped when used as the part of a ...

00:24
if Number("1") didn't work I dont' think parseInt will be much better
no - that's after the fact
I need the _.sortBy() to sort an int and not a string/boolean
I need to edit the object to convert each one to an int then do the sort
you might have to map the object values to a number from a string
@jbolanos You can use a custom comparator that compare them as number. Or you can mass convert them before sort as you said, with a loop.
underscorejs _.map()?
arr = arr.map(item => {
  item.blah = Number(item.blah);
  return item;
});
00:26
@jbolanos where where you using Number? are you doing _.sortBy(arr, (t) => parseInt(t.Sort, 10)) ?
you don't need to map ><
it lets you specify the comparison
I don't know underscore.
so, probably listen to david
but parseInt is restrictive. parseFloat or Number if you don't actually need parseInt
I'd rather use Number since it will always be whole numbers
@jbolanos That was a joke, right?
@david This worked. Of course It took a minute because I can't spell.
unfortunately, Number("") is 0
@rlemon starting p90x with my roommate in 30 minutes
we just took the preworkout
the transformation has begun
00:42
lol nice
BRO OUT!
Heh, I started working with a personal trainer about two months ago
I'm already starting to tense up lol we took this shit called maximum assault LOL
I just ate less and lost 57 lbs
I can't stop saying brother like hulk hogan
BROTHURRRRR
I drank less beer + worked out a bit
++progress
00:44
I'm gonna take a before and after pic. This and eating right? Matt says were gonna be ripped in 90 days
Next year I reach my goal of 190 lbs (6'1"). Only 27 more pounds to go
So I'm struggling with how to structure my app now
Should player.damage(id, amount) load the player's health from redis, decrease it by amount, and then store it?
Well, ideally wouldn't having the player instance already loaded work, so that you don't have to pass in the id?
Yeah
00:48
@SterlingArcher hah
been doing that again for 3 weeks
Or should I do player.damage(10) then player.heal(5) then redis.store(player)
chest and back today bruh
actually pushing todays to tomorrow though
i.e. doing everything in memory then saving it the state at the end of a request
@Meredith the first one. all in one action.
or the last option, with the 'transaction' kinda all-in-one
the second one might need 'locks', which are a whole thing
Yeah the first one is how I'd do it with sql
00:51
wait, I misread the first option.
if redis the single source of truth for the health?
It could be
is there a way to combine these?
getTerms = _.filter(obj, (t) => t.TopSearchTerm == '1');
sortTerms = _.sortBy(getTerms, (t) => Number(t.Sort));
But I'm glad you mentioned that
Because I guess the real question
Is if my single source of truth should be redis or something in memory
If it's not redis, what is redis doing with the value?
Just stores it in case the server crashes
00:54
so it's only read on start?
Well right now it's not anything
I've barely written any code
I ask because redis can be used to keep state shared by server instances. When you do that the order or reads/writes matter. But it sounds like you want it just as a backup for a single server?
Yeah right now I'm only using 1 server
OK, then, you could still have concurrency issues if you are serving multiple requests are once.
Yeah
I'll store every transaction
Instead of batching them
00:58
I'm going to push you toward talking to the redis server as few times as possible. This might mean a single 'script' that reads, compares and decides to subtract from health.
To prevent multiple requests overlapping and leading to 'double withdrawal'
i think redis has single commands to increment a value by another..
Oh I get what you mean
Otherwise, how do you handle it when 1 request wants the heath of a person "to update it" and the other also gets the health? One of them will be out-of-date.
01:01
Basically, you introduce the problems you would have without redis, but with multiple threads sharing state.
I'm pretty sure the redis library for node does batch requests if you make lots at once
you can do transactions with MULTI and EXEC
for something that's updated really often like player health you might want to pull that out into a game:<gameid>:player:<playerid>:component:health field that you can inc/decr
agree
Yeah my plan is to have player:${playerid}:health
Evening chaps
evening lix
01:13
How's it going @david
not too bad
having fun with react
and trying to get the damn router to tell me its secrets
01:32
I'm converting an html file to a string, appending a meta tag, then attempting to serve the string from my server, but something about converting the html is breaking all my scripts?
I'm doing this server side so I didn't think it would matter but sure enough, just serving the html without any kind of conversion works fine...
Before the webpage interprets the code based from the headers it is just one big string in essence.
that's what I thought, so why would it not handle my scripts?
better yet, only one script is ever loaded, the first one, regardless of which is in first place
I'm presuming your running some kind of node server?
no
using fantom (from fantom.org)
are you literally appending it or are you inserting it into the right place in the head?
01:37
head
compare the script you serve 'normally' with your man-handled one to see what is different
the difference is I'm appending a meta tag
are you inserting it correctly? you're not forgetting to close the tag or anything?
to the head
that's the difference you intend, but you claim yourself, it's not quite right
01:39
i don't follow
Yeah, can you disclose what exactly is broken here?
show us the code that adds the tag
No page loading? Errors from the interpreter?
and show us any errors you get
yeah one sec
no errors, but I can view source and see that it's blacked-out, no hyperlink
01:40
yea, the source is wha tI wanted you to compare
Can you gist the part that's erroring out and your source for appending
the source is in fantom, not javascript, but sure
gist: append meta tag, 2016-12-20 01:44:22Z
indexFile := this.typeof.pod.file(`/res/client/index.html`)
indexHtmlAsElem := HtmlParser().parseDoc(indexFile.readAllStr)
XElem projNameMetaElem := XElem("meta")
projNameMetaElem.addAttr("name", "projectName")
projNameMetaElem.addAttr("content", projName)
indexHtmlAsElem.elem("head").add(projNameMetaElem)
res.headers["Content-Type"] = "text/html"
strResp := indexHtmlAsElem.writeToStr
res.headers["Content-Length"] = strResp.size.toStr
res.statusCode = 200
indexHtmlAsElem.write(res.out)
updated the gist with the html as well
i'm contemplating if it's worth a shot to just write the new str to an in-memory file and serve the file to see if that bypasses the issue altogether
so system.js works, but not the other files?
right
after the append
Is it possible that the location of those .js files aren't available as they haven't been made static when it serves the files?
01:50
i expected the some some malformed html in the modified version..
ohh right, lix, good call
a changing url
@lix I don't completely understand what you're saying here, the location of those .js files?
what are the urls of the original and modified versions?
the exact same
and the client never sees the unmodified version
the url is just localhost
got me
have you tried adding "../foo.js"
So it always chooses the top directory when serving those files
01:54
Error while performing the database query: Error: Handshake inactivity timeout
then refreshed the page and everything is ok...
?
So how do I get player:playerid:health and player:playerid:maxHealth in one go?
I know I could use KEYS but I'm not supposed to do that
@Meredith MGET key1 key2
@lix
it's serving the files just fine
except for the bottom ones lol
<script src='build.js'/>
<script src='jspm.config.js'/>
These correct?
correct
attached screenshot to show how crazy this is
01:58
hello
maybe <script></script>?
I'm not sure how to do that with jade (now pug)
@david Ok thanks
I'll give that a shot though
anyone familiar with react could help me answering stupid/tutorial/conceptual questions?
01:59
How do I use it with node?
Apparently mget is not a function

« first day (2257 days earlier)      last day (2913 days later) »