{"action":"created","issue":{"url":"https://api.github.com/repos/StackExchange/StackExchange.Redis/issues/333","labels_url":"https://api.github.com/repos/StackExchange/StackExchange.Redis/issues/333/labels{/name}","comments_url":"https://api.github.com/repos/StackExchange/StackExchange.Redis/issues/333/comments","events_url":"https://api.github.com/repos/StackExchange/StackExchange.Redis/issues/333/events","html_url":"https://github.com/StackExchange/StackExchange.Redis/issues/333","id":125747269,"number":333,"title":"GetHashCode stability","user":{"login":"johnnycardy","id":904610,"avatar_url":"https://avatars.githubusercontent.com/u/904610?v=3","gravatar_id":"","url":"https://api.github.com/users/johnnycardy","html_url":"https://github.com/johnnycardy","followers_url":"https://api.github.com/users/johnnycardy/followers","following_url":"https://api.github.com/users/johnnycardy/following{/other_user}","gists_url":"https://api.github.com/users/johnnycardy/gists{/gist_id}","starred_url":"https://api.github.com/users/johnnycardy/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/johnnycardy/subscriptions","organizations_url":"https://api.github.com/users/johnnycardy/orgs","repos_url":"https://api.github.com/users/johnnycardy/repos","events_url":"https://api.github.com/users/johnnycardy/events{/privacy}","received_events_url":"https://api.github.com/users/johnnycardy/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2016-01-09T08:49:45Z","updated_at":"2016-01-09T09:36:50Z","closed_at":null,"body":"A hash code method is stable if it returns the same values reliably outside the current app domain. In particular, [.NET's GetHashCode is not stable](https://msdn.microsoft.com/en-us/library/system.string.gethashcode(v=vs.110).aspx).\r\n\r\n`RedisValue` is unstable when it's an `int`:\r\n - when `valueBlob == IntegerSentinel`, `int.GetHashCode()` is returned which is unstable\r\n - otherwise a custom stable hash algorithm is used\r\n\r\n`RedisKey` is unstable when it's a `string`:\r\n - `GetHashCode` combines two parts - the aforementioned custom stable hash algorithm of `RedisValue`, and when `RedisKey` is a `string`, `string.GetHashCode()` which is unstable.\r\n\r\nMy questions are:\r\n- why is the implementation of RedisKey different from RedisValue?\r\n- why is the custom RedisValue.GetHashCode(byte[] value) function not always used to provide stability all the time?\r\n- are there backwards compatibility issues in changing the behaviour?\r\n"},"comment":{"url":"https://api.github.com/repos/StackExchange/StackExchange.Redis/issues/comments/170215221","html_url":"https://github.com/StackExchange/StackExchange.Redis/issues/333#issuecomment-170215221","issue_url":"https://api.github.com/repos/StackExchange/StackExchange.Redis/issues/333","id":170215221,"user":{"login":"mgravell","id":17328,"avatar_url":"https://avatars.githubusercontent.com/u/17328?v=3","gravatar_id":"","url":"https://api.github.com/users/mgravell","html_url":"https://github.com/mgravell","followers_url":"https://api.github.com/users/mgravell/followers","following_url":"https://api.github.com/users/mgravell/following{/other_user}","gists_url":"https://api.github.com/users/mgravell/gists{/gist_id}","starred_url":"https://api.github.com/users/mgravell/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mgravell/subscriptions","organizations_url":"https://api.github.com/users/mgravell/orgs","repos_url":"https://api.github.com/users/mgravell/repos","events_url":"https://api.github.com/users/mgravell/events{/privacy}","received_events_url":"https://api.github.com/users/mgravell/received_events","type":"User","site_admin":false},"created_at":"2016-01-09T09:36:50Z","updated_at":"2016-01-09T09:36:50Z","body":"It is not required that a hash-code be stable between app-domains. There is\nno valid use of GetHashCode() that would require that. SE.Redis does not\nintentionally aim to be unstable across app-domains, bit it also doesn't\nexplicitly attempt to be stable between them.\n\nThe byte[] method is not always used specifically because the data is not\nalways a byte[].\n\nThere is no expectation for GetHashCode() to remain equal between runs, so\nno: there are no backwards compatibility issues with changing the\nimplementation. However, I would want to see an actual real-world\njustification before attempting (or merging) any changes.\nOn 9 Jan 2016 8:49 am, \"Jonathan Cardy\" <notifications@github.com> wrote:\n\n> A hash code method is stable if it returns the same values reliably\n> outside the current app domain In particular, NET's GetHashCode is not\n> stable\n> <https://msdnmicrosoftcom/en-us/library/systemstringgethashcode(v=vs110)aspx>\n>\n> RedisValue is unstable when it's an int:\n>\n>    - when valueBlob == IntegerSentinel, intGetHashCode() is returned\n>    which is unstable\n>    - otherwise a custom stable hash algorithm is used\n>\n> RedisKey is unstable when it's a string:\n>\n>    - GetHashCode combines two parts - the aforementioned custom stable\n>    hash algorithm of RedisValue, and when RedisKey is a string,\n>    stringGetHashCode() which is unstable\n>\n> My questions are:\n>\n>    - why is the implementation of RedisKey different from RedisValue?\n>    - why is the custom RedisValueGetHashCode(byte[] value) function not\n>    always used to provide stability all the time?\n>    - are there backwards compatibility issues in changing the behaviour?\n>\n> —\n> Reply to this email directly or view it on GitHub\n> <https://github.com/StackExchange/StackExchange.Redis/issues/333>.\n>\n"}}